Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Deleting a Directory Tree

Question:
I want to delete and entire directory tree. I do not know how big the directory is, how many sub-dirs that it has, etc. I am not using a form and listing directories, this is some code in a module. All I know is the name of the top directory.

Answer:
The DOS command to do this is "deltree". If you do a Shell statement to COMMAND.COM, you can run that command on the directory. For instance, the code you would want to do is this: Shell "COMMAND.COM /C DELTREE C:\WINDOWS". (That example could be a bit dangerous, but you get the idea.) I believe there might be API calls to do this, but you'd have to be careful with versioning if you were planning on releasing a 16- and 32-bit version of the program. The hard way to do it (if you wanted to be sure) is to write a recursive directory search that goes through and uses the "Kill" statement and the "RmDir" function to delete any files in a directory and then remove it. You might be able to fake something like this by using a hidden drive/dir/filelist box combination.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date