Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Directories 3

Status
Not open for further replies.

sacsac

Programmer
Dec 10, 2000
177
GB
Does anyone have suggestions for some code to remove a directory plus all its subdirectores and file?
 
..using DOS command

rd "directory" /S/Q

..

something like

Shell("rd 'directory' /S/Q")

 
You can also use the File System Object to delete a folder.

Call CreateObject("Scripting.FileSystemObject").DeleteFolder("[!]C:\TekTips\Delete Folder[/!]", True)

Of course, you'll need to chang the folder you want to delete. The TRUE at the end of the line spefies whether read-only files are deleted.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Or you can shell to a .bat file. If c:\test.bat looks like
test.bat said:
rd c:\test\fred /s /q
you can call it with
Code:
Shell("c:\test.bat")

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Thanks everyone! Especially gmmastros - I've used your code as it seems the neatest!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top