devxlogo

Deleting a Directory Tree

Deleting a Directory Tree

Question:
I want to delete and entire directory tree. I do not knowhow big the directory is, how many sub-dirs that it has, etc.I am not using a form and listing directories, this is somecode 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.

See also  Comparing different methods of testing your Infrastructure-as-Code
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist