Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing A Directory
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00608966
Message ID:
00611120
Vues:
27
>>>I am writing a program that needs to check for the existence of a particular directory. It then needs to delete everything underneath that direcotry (to include other folders) and the very last step is to delete the directory itself.
>>
>>Jeffrey,
>>
>>With the Windows Script Host it's a snap. Once you've verified the existence of the directory with the DIRECTORY() function
oFSO = CREATEOBJECT("Scripting.FileSystemObject")
>>* lcdir is the directory to delete
>>oFSO.DeleteFolder(lcdir, .T.)
Note that this deletes the folder, files, any sub-folders completely. IOW, they're not sent to the Recycle bin. The .T. parameter forces the deletion of any read-only files. All other file, including hidden and system folders are deleted regardless.
>*******
>I don't think you need a switch (in fact I don't think you can use a switch here)
>
>oFSO.DeleteFolder(lcdir)     && delete the folder, subfolders and files
>oFSO.DeleteFile(lcfile, .T.) && delete any file, even read-only
>
From the Scripting Runtime SDK on the second parameter:

force
Optional. Boolean value that is true if folders with the read-only attribute set are to be deleted; false (default) if they are not.

IOW, if a folder is marked read-only you need to use the switch. Otherwise, if one is a COM error will occur. Since VFP doesn't have access to the scripting error handler, in this case, it's better to be safe than sorry.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform