Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stonefield Database Dictionary - Going Forward
Message
From
28/09/2006 12:19:48
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01156596
Message ID:
01157887
Views:
32
>>pardon me for jumping in. Your code show why I NEVER use the file() function, because it is simply a dangerous function to use. Even if you specify a directory, it always checks in all the directories which is specified in set path to. So file('c:\test\yourfile.ext') will show true even if there is no c:\test\yourfile.exe on your HD, as long as you have a file called yourfile.ext in your VFP path.
>
>PMFJI, but that is not true. If you specify a path and the file is not present, FILE() returns false as the following code demonstrates.
LOCAL lcCurDir
>lcCurDir = SYS(5) + SYS(2003)
>
>* Assumes you have directory C:\temp
>CD c:\temp
>MD dir1  && Create C:\temp\dir1
>MD dir2  && Create C:\temp\dir2
>
>* Create table yourfile.ext in dir1
>CD c:\temp\dir1
>lnFileHandle = FCREATE( "yourfile.ext")
>=FCLOSE( lnFileHandle)
>
>SET PATH to C:\temp\dir1  && dir1 has yourfile.ext in it
>CD C:\temp\dir2  && dir2 has no files in it
>
>* Use FILE() to check if yourfile.ext exists
>?"Path = " + SET( "path") && Confirm path points to C:\temp\dir1
>?"Curdir = " + SYS(5) + SYS(2003)  && Confirm current directory is C:\temp\dir2
>?FILE( "yourfile.ext")  && True because yourfile.ext is in the path
>?FILE( "c:\temp\dir2\yourfile.ext")  && False because yourfile.ext is not in dir2
>
>CD &lcCurDir
You get the same result with the more generic SYS(2003)
?FILE( ADDBS( SYS(2003)) + "yourfile.ext")  && False because yourfile.ext is not in dir2
Well, try my code! Feel free to change the paths according to your setup. In this case p: is my default drive, and the path includes p:\data\
STRTOFILE('aaa','p:\data\xyz.xyz')
?FILE('p:\xyz.xyz') &&.T. which is WRONG
?FILE('p:\data\xyz.xyz') && .T. which is correct
?adir(dummy,'p:\xyz.xyz')>0 && .F. which is correct
?adir(dummy,'p:\data\xyz.xyz')>0 && .T. which is correct
NB! I have no p:\xyz.xyz file!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform