MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Using Excel Macro to Browse through folders and delete selectively ?


Posted by Dave on January 27, 2002 10:50 PM


I'm unsure if an Excel macro is my best option here, but I have about 3500 folders (with very cryptic names) in a certain directory (from a data recovery program, I can't believe I deleted my hard drive!!) that I need a program to run through, look for certain conditions (eg. the folder contains a *.doc or *.xls file), and deletes or keeps the folder if it meets these certain conditions.

I know Excel has access to certain methods such as deletefolder, but what about functions that allow me to manipulate a list of folders e.g:

for each folder in currentfolder
if !contains(*.xls || *.doc)
delete (folder)
next folder

How do I retrieve and manipulate this list of folders in an excel macro?

thanks in advance !!


Posted by Bariloche on January 28, 2002 5:05 AM

Dave,

You should be able to adapt my response to a similar question (17496.html) to your needs.


enjoy

I'm unsure if an Excel macro is my best option here, but I have about 3500 folders (with very cryptic names) in a certain directory (from a data recovery program, I can't believe I deleted my hard drive!!) that I need a program to run through, look for certain conditions (eg. the folder contains a *.doc or *.xls file), and deletes or keeps the folder if it meets these certain conditions. if !contains(*.xls || *.doc) delete (folder) next folder

Posted by Ivan F Moala on January 28, 2002 6:19 AM

Dave
Excel can do this via Kill & RmDir
However these commands can be dangerous in that
once they are deleted you cannot (without the use
of a File Utility prgm) get these back.
What I'm saying is that Yesyou can code it such that excel will search all folders for your spcified file extensions andif not found delete
the folder.....however if the coding is in error
you risk the chance of loosing some data.

I would personnally stere clear of these commands
and use an API function that removes the folders
to the recycle bin. The code to do this ??...
I have some code but not tested....wouldn't like
to test it on your drive :-)


Ivan


I'm unsure if an Excel macro is my best option here, but I have about 3500 folders (with very cryptic names) in a certain directory (from a data recovery program, I can't believe I deleted my hard drive!!) that I need a program to run through, look for certain conditions (eg. the folder contains a *.doc or *.xls file), and deletes or keeps the folder if it meets these certain conditions. if !contains(*.xls || *.doc) delete (folder) next folder