Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BUG in VFP with FILE() function?
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00952700
Message ID:
00952797
Views:
16
Thanks for the info and examples. Very helpful. The reason for using short path names is too detailed to go into here, but has to do with backward compatibility + displaying an appropriate pick list for users. The ADIR() approach works. In fact, even passing the long file name through the WinAPI GetShortPathName works. If a blank string comes back, the file doesn't exist. I'm just puzzled why the File() function does not work with an unambiguous short path name.

>The FILE() function has some behavior that came come out when you are working with paths, but it doesn't seems like your problem. Why are you using the short path? VFP can use the LFN:
>
>
>
>#DEFINE UsingAPI .T.
>#IF UsingAPI
>DECLARE INTEGER ShellExecute ;
>    IN SHELL32.DLL ;
>    INTEGER nWinHandle,;
>    STRING cOperation,;
>    STRING cFileName,;
>    STRING cParameters,;
>    STRING cDirectory,;
>    INTEGER nShowWindow
>#ENDIF
>
>
>lcPSPPath = "C:\Program Files\Jasc Software Inc\Paint Shop Pro 9\Paint Shop Pro 9.exe"
>
>IF FILE(lcPSPPath)
>    CD (JustPath(lcPSPPath))
>     #IF UsingAPI
>        ShellExecute(0, "Open",JustSTem(lcPSPPath), "", JustPath(lcPSPPath), 1)
>     #ELSE
>         RUN (JustSTem(lcPSPPath))   && Just Run with internal VFP run command
>    #ENDIF
>ENDIF
>
>
>
>Another options to the File() function:
>
>Option 1
>Remove the paths...
>
>Function SureFile
>
>  LParameters tcFileName
>  Local lcOldPath
>  Local llRetValue
>
>       lcOldPath = SET("PATH")
>       SET PATH TO
>          llRetValue = File(m.tcFileName)
>       SET PATH TO &lcOldPath
>      Return llRetValue
>EndFunc
>
>
>Option 2
>Use the ADIR() function, which doesn't have the behaviors of the FILE function
>
>Function SureFile
>
>  LParameters tcFileName
>   RETURN (ADIR(laDummy, m.tcFileName) > 0)
>EndFunc
>
>
>Option 3
>Using SYS(2000) function
>
>Function SureFile
>  LParameters tcFileName
>  RETURN NOT EMPTY(SYS(2000,m.tcFileName))
>ENDFunc
>
>
>Option 4
>Using API
>
>*** In your init program, just once *****
>declare Integer GetFileAttributes in win32api string @
>****************************************
>
>Function SureFile
>
>   LParameters tcFileName
>       return (GetFileAttributes(@m.tcFileName)  <> -1)
>EndFunc
>
>
>
>HTH
>>The file: "C:\Program Files\Jasc Software Inc\Paint Shop Pro 9\Paint Shop Pro 9.exe" defnitely exists on my PC.
>
>>This returns TRUE as expected:
>
>FILE("C:\Program Files\Jasc Software Inc\Paint Shop Pro 9\Paint Shop Pro 9.exe")
>
>>This is the short file name for the file: "C:\PROGRA~1\JASCSO~1\PAINTS~2\PAINTS~1.EXE"
>>When I try to RUN &cShortFileSpec, it works.
>>If I do DIR "C:\PROGRA~1\JASCSO~1\PAINTS~2\PAINTS~1.EXE", it shows
>>... but FILE("C:\PROGRA~1\JASCSO~1\PAINTS~2\PAINTS~1.EXE") returns FALSE!!!!! File is neither >SYSTEM nor HIDDEN.
>
>>WTF? Bug or not?
Previous
Reply
Map
View

Click here to load this message in the networking platform