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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting nested folders (sub-folders) at the click of a button

Status
Not open for further replies.

dubble07

Programmer
May 8, 2002
12
CA
Firstly, thanks to those who helped with the deleting files question i had. Works like a charm! All files delete nicely, and with a little tinkering on my part, they also delete from all subfolders.

My problem now, involves deleting folders. The RmDir only works when a folder is empty, else it errors. I have one big long chain of subfolders within the folder i want to delete. Does anyone have an idea on some sort of looping structure that will go through this chain (to the lowest level) and delete each and every folder. Even bettter would be some sort of function that would wipe out the whole folder structure irregardless of whats in there.

Any ideas folks??

..and thx!

 
Hello Jim
Sorry I don't have the opportunity at the moment to create a solution for you but if you look into using the DeleteFolder method of the FileSystemObject object (it might be FolderDelete, can't remember) it should give you what you need. It will delete a specific folder and everything in it. Permanently! The second parameter allows you to force deletion of read only files.

If you want to delete sub folders from a folder ie empty a folder but keep it I would suggest one of the following

1. Either delete the folder completely then recreate it in the same location. No guarentee this will work from the point of view of other items referencing the folder

2. Loop through all items in the folder and delete. Slower but safer. Maybe!

Be warned - if this method crashes halfway through there is no way back (other than backups). Anything deleted is gone - not to recycle bin if you're working on a local machine.

Hope this gets you on your way!

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top