Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
If a file exists
Message
From
16/03/2005 05:49:35
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00996204
Message ID:
00996217
Views:
19
>>Does anybody know how I can check programmatically if a file exists in a certain location. I have a path and file stored to a variable and i want to check if it exists. For example:
>>
>>C:\program files\pictures\dress.tif
>>
>>If this file exists in this location I want to issue a messagebox command.
>>
>>Any help would be greatly appreciated.
>
>
>Neil, Keep in mind that If You use a FILE() function You can be confused if the file You search is placed in folder stored in SET PATH TO..., but You want to check the existing of a file in some different folder.
>make a folder named TEST in C:
>Place dress.tif here, and use a FILE() with path that You are shure Dress.TIF not exists.
>and do:
>
>*** In MyDir there is no file dress.tif
>SET PATH TO c:\test
>? FILE("C:\MyDir\dress.tif")  && .T. ????????????????
>
>
>a workaround:
>
>
>** If You want to use FILE() function
>m.old_path = SET("PATH")

Borislav, 

you've got a good point, which I forgot. However, you can set compatible off to fix this. 
<pre>lcComp=set('compatible')
set compatible on
llFile=FILE("C:\MyDir\dress.tif")
set compatibell &lcComp
if llFile
  whatever
endif
But an easier solution is adir()
if adir(dummy,"C:\MyDir\dress.tif")>0
  whatever
endif
>SET PATH TO
>? FILE("C:\MyDir\dress.tif") && .F.
>SET PATH TO (m.old_path)
>**** End with FILE() function
>
>*** Other way is to use SYS(2000) function
>
>? .NOT. EMPTY(SYS(2000, "C:\MyDir\dress.tif")) && .F.
>
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform