How can I check a directory to see whether it exists?
If exists, how can I delete all files & sub folders under that directory?.
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Printable View
How can I check a directory to see whether it exists?
If exists, how can I delete all files & sub folders under that directory?.
Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!
dir command will tell you if it exists or not. I don't know any direct way of deleting every file an subdir in that dir but you could always go trough every single subdir having a procedure call itself to search trough subdirs and delete all file and remove the subdir. I have some related code if you want
Just a little DOS command, instead of using a recursive function to delete everything under a directory in VB (which works, but is way too much work), use the shell command with Deltree, as follows:
It just sooo much easier! WHY doesn't VB or API include this command???Code:Call Shell("DELTREE /Y " & sDirectory, vbHide)
BTW, make sure that the path that you specify does NOT include a trailing backslash, if it does then it will only delete everything under the specified directory and not the directory itself, for example:
wrong: sDirectory = "C:\TEMP\TEST\"
right: sDirectory = "C:\TEMP\TEST"