1. Ashutosh Varshney
  2. PowerBuilder
  3. Wednesday, 19 July 2017

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?

Who is viewing this page
Accepted Answer
Neil Garcia Accepted Answer Pending Moderation
0
Votes
Undo

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
Thanks Neil! Your workaround is quite helpful.

  1. Ashutosh Varshney
  2. Friday, 21 July 2017
There are no comments made yet.
  1. Thursday, 20 July 2017
  2. PowerBuilder
  3. # Permalink
Lars Mosegaard Accepted Answer Pending Moderation
0
Votes
Undo

I always use GetFileOpenName...

Comment
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. Ashutosh Varshney
  2. Thursday, 20 July 2017
If you try FileOpen it should return an error for a directory or invalid file. Then immediately call FileClose if it worked.

  1. Roland Smith
  2. Thursday, 20 July 2017
There are no comments made yet.
  1. Thursday, 20 July 2017
  2. PowerBuilder
  3. # 1
  • Page :
  • 1


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