Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to know if directory already exists before MKDIR?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00155183
Message ID:
00155197
Vues:
27
>want to create a temporary directory, if it does not already exist. if it does exist then i want to do nothing. what is a good method?

You can use ADIR and MD or use the Windows API (see below). You could also just do the MD and let the error event or ON ERROR catch it. I prefer the Windows API, because I get an error code if it fails.

* Use ADIR and MD

LOCAL laDir

IF ADIR(laDir, "C:\Temp\MyDir", "D") = 0
MD "C:\Temp\MyDir"
ELSE
* Directory does not exist
ENDIF

* Use Windows API

DECLARE Integer CreateDirectory IN Win32API ;
String cPathName, String @cSecurityAttributes

IF CreateDirectory("c:\Temp\2", .NULL.) = 0
* Could not create directory (probably because it exists)
ENDIF
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform