1. Shrinkhla Bhargava
  2. PowerBuilder
  3. Friday, 18 February 2022 09:26 AM UTC

Hi,

I am using Fileexists function to locate that whether the given file exists or not.

I am using the below code :

String ls_path 

Boolean lb_exists

ls_path = 'abc.txt'

lb_exists = Fileexists(ls_path) 

Question : In my case, it giving true in lb_exists variable. So I want to know the absolute path this Fileexists function is using in case when we pass only file name ?

Is it using current directory absolute path from where application is running ?

Regards,

Shrinkhla

Brad Mettee Accepted Answer Pending Moderation
  1. Friday, 18 February 2022 15:30 PM UTC
  2. PowerBuilder
  3. # 1

Whenever you use File Functions, you should use full pathing so you always know exactly where you're dealing with files.

GetCurrentDirectory() will return the current location the app is pointed to, NOT the app path. At app startup, Current Directory will be the same as App Path, but there's no guarantee it will stay there if there are any Open/Save file operations being used where user input is given.

FileExists, FileOpen, GetFileOpenName, GetFileSaveName, DirList, DirSelect, DirectoryExists and any other File oriented operation (include import/export of datawindow data) will always default to the "Current Directory".

If a user has changed directory (to save/open a file in an alternate place), current directory will be that alternate place unless you have called ChangeDirectory() to set it back to a known location.

 edit: I did recall one other thing. If the app starting directory is different than the app location on a shortcut, that will be the starting default directory.

Comment
  1. Mark Goldsmith
  2. Friday, 18 February 2022 21:34 PM UTC
Bang on Brad...the other exception I would add in addition to using ChangeDirectory() to set it back to a known location is with GetFileOpenName and GetFileSaveName when the aFlag option OFN_NOCHANGEDIR has been provided.
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 18 February 2022 10:31 AM UTC
  2. PowerBuilder
  3. # 2

Hi Shrinkhla,

A short test with Process Monitor (by Sysinternals) shows, that it searches for the file not only in the current directory but also in all directories listet in PATH variable.

BTW, current directory can also be a different directory from app dir!

HTH,

René

 

Comment
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.