1. Ashutosh Varshney
  2. PowerBuilder
  3. Wednesday, 19 July 2017 20:33 PM UTC

Hello,

I have created a window which prompts the user to enter a file name and then this file is used for further processing. To make sure that the specified file exists, I call the FileExists function. 

If FileExists (sle_selFile.Text) Then
    MessageBox ('FileExists', 'Yes')
Else
    MessageBox ('FileExists', 'NO')
End If

Here is my problem - if the user selects a valid directory say 'C:\Windows\', FileExists returns True. FileExists behaves like DirectoryExists. Am I missing something?

Accepted Answer
Neil Garcia Accepted Answer Pending Moderation
  1. Thursday, 20 July 2017 17:18 PM UTC
  2. PowerBuilder
  3. # Permalink

I think it's been like that, e.g. FileExists(directoryname) returns TRUE.

You can ensure that a filename is entered by checking like:

If FileExists(sle_selFile.text) and NOT DirectoryExists(sle_selFile.text)

 

Comment
  1. Ashutosh Varshney
  2. Friday, 21 July 2017 21:07 PM UTC
Thanks Neil! Your workaround is quite helpful.

  1. Helpful
There are no comments made yet.
Lars Mosegaard Accepted Answer Pending Moderation
  1. Thursday, 20 July 2017 01:07 AM UTC
  2. PowerBuilder
  3. # 1

I always use GetFileOpenName...

Comment
  1. Ashutosh Varshney
  2. Thursday, 20 July 2017 14:14 PM UTC
Thanks Lars.

But my interface allows users to either select a file using GetFileOpenName or type the path into an sle. And I need to check if the file exists before proceeding.

  1. Helpful
  1. Roland Smith
  2. Thursday, 20 July 2017 14:38 PM UTC
If you try FileOpen it should return an error for a directory or invalid file. Then immediately call FileClose if it worked.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.