Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to check if a file exists
Message
De
23/10/2017 11:34:56
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01655128
Message ID:
01655152
Vues:
74
>I need to check if a file c:\global\*.doc exists - what is the correct code for this?

If you know the particular filename use file(). If you want to check if any *.doc exists, you might use adir. adir builds an array filled with all matching *.doc, which could be a big array if you have many files. IMO the best way is

llFound = !empty(sys(2000,"c:\global\*.doc"))

That will tell you if there are any *.doc files. The issue is, what do you plan to do next? If you want to process all *.docs, the array may help. Or sys(2000) could be used to check for a file and then to process the remaining. That works really well and there is no upfront time spent building a potentially huge array.
lcFile=sys(2000,"c:\global\*.doc")
DO WHILE !EMPTY(m.lcFile)
  *do something with m.lcFile
  *get the next file - that's what the ,1 is for.
  lcFile=SYS(2000,"c:\global\*.doc",1)
ENDDO
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform