Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sure_File()
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00927285
Message ID:
00927590
Views:
20
>>>>Hi.
>>>>As File() searches along SET PATH as well what is a simple way to assertain that the file really exists where i am looking for it?
>>>>I was thinking FOPEN(), but...
>>>>Thank you.
>>>
>>>Kamil,
>>>
>>>Gregory's way searches the Windows path as well. If you want to know if the file exists without searching any path
FUNCTION FileNoPath(tcFilename AS String)
>>>
>>>* tcFilename is the fully qualified file name
>>>
>>>  LOCAL llresult, lcpath
>>>  lcpath = SET("PATH")
>>>  SET PATH TO
>>>  llresult = FILE(tcFilename)
>>>  SET PATH TO (lcpath)
>>>  RETURN llresult
>>>ENDFUNC
>>
>>hi George,
>>
>>My first thought reading your reply was: Hell, I didn't suspect that.
>>
>>So, I've done a few tests and all of the examples below return FALSE.
>>Also, the doc about GetFileAttributes() does not mention a search in the windows path. (while CreateProcess() does)
>>
>>Anything I am missing ?
>>
>>
>>?FileExists('system.ini')  && in C:\Windows
>>?FileExists('kernel32.dll') && in C:\WIndows\system32
>>?FileExists('command.com')  && in C:\WIndows\system32
>>
>>
>>from the (dos)command window
>>
>>echo %path%
>>C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;c:\progra~1\isabel\bin;c:\progra~1\isabel\maxware;C:\PROGRA~1\ATITEC~1\ATICON~1;C:\bin;C:\PROGRA~1\Java\JDK15~1.0\bin
>>
>>
>>In addition, I believe that when running an exe and SET PATH TO (empty), any file included in the exe will be found with FILE()
>
>Gregory,
>
>The FILE() function maps to the API function FindFirstFile().
>
>According to the Platform SDK:
>
>In rare cases, file attribute information on NTFS file systems may not be current at the time you call this function. To obtain the current NTFS file attributes, call GetFileInformationByHandle.
>
>It seems to me that my suggestion is a lot cleaner than using the internal Windows API.
_________________________________________________________________________________________________
George,

Let's recap

Kamil wants to find out if a file exists where he wants it avoiding the PATH search

GetFileAttributes() suits me.

You anwer 2 things (1) GetFileAttributes() searches along the windows path and (2) suggest setting the PATH to '' before applying FILE()

(1) The tests I have done show that GetFileAttributes() does not search along the windows path

(2) When you run in an exe or an app, setting the PATH to '' prior to using FILE() searches the files included in the exe/app and may return wrong results whereas GetFileAttributes() will return -1

The rare cases you refer to apply to the FindFirstFile() function and the FileAttributes returned by it (from the SDK)
Then why would FILE() be much cleaner than GetFileAttributes() ??? (since FILE() uses FindFirstFile() which is the internal Windows API)
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform