Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best Way to Delete a Directory and all its contents?
Message
 
 
À
28/10/2003 13:47:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00843644
Message ID:
01409874
Vues:
79
Interesting, but I don't think effective with many files in the directory.

>Sometimes, I do it the LONG way completely within VFP:
>
>
>mypath="C:\tracy"
>=getfolders(mypath)
>IF !DIRECTORY(mypath)
>    RETURN .T.
>ELSE
>   MESSAGEBOX("could not delete the directory: "+mypath)
>ENDIF
>
>function GetFolders
>    parameters mypath
>    local lstfiles[1], dirnum,i
>    ? mypath
>    dirnum = adir(lstfiles,mypath+"\*.*","D") 
>    for i = 3 to dirnum
>        if "D"$lstfiles(i,5)
>            GetFolders(mypath+"\"+lstfiles(i,1))
>        endif
>    next
>    on error do fileerr
>    delete file (mypath+"\*.*")
>    rd (mypath)
>    on error
>return(.t.)
>
>PROCEDURE FILEERR
>    myError = 1
>    RETURN
>
>
>Just another option as you asked.
>
>
>
>>Hi,
>>
>>We've got a web app based on West Wind Web Connection. Many clients will be using the same app. Every once in a while we upgrade our app - and that may include new fields. We are going to upgrade the tables by backing up the clients table folder. (renameing it to tables.bak) Then we create a new tables folder. We have a client called "setup" which is just blank, updated tables. We copy the tables, etc., in the clients tables folder. Then we append the data from the old structures into the new updated tables and populate the new fields.
>>
>>Before we can backup the old tables we need to remove the old backup. (if it exists)
>>
>>I need to write code to delete an directory and all its contents. (including sub folders) It has to be able to run without any user intervention.
>>
>>I've looked at two possible ways to do this.
>>1. The SHFileOperation API function. It says that you may see "windows file operation animations" Does that mean you have answer "yes" to delete the folder?
>>2. Use windows file scripting object. I found some example code of this on the west wind messageboard that looks fairly easy. I know its dangerous to have this enabled, but we already use the file scripting object elsewhere in the code...
>>
>>Just wondering what your thoughts on this were...Or if there is another way that I don't know about.
>>
>>Thanks,
>>Chris
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform