|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Delete all files of certain type in folder and all subfolders
I'm trying to make a .vbs script that will search a folder and all of the
folders contained within for any files of a certain extension, and delete them. What I have right now is the text: Const DeleteReadOnly = TRUE Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile("C:\Woo\*.txt"), DeleteReadOnly which I got from the Microsoft Scripting library. On Nov 6, 3:09 am, Matt <M***@discussions.microsoft.com> wrote:
> I'm trying to make a .vbs script that will search a folder and all of the To do that you would need to either write a recursive search routine> folders contained within for any files of a certain extension, and delete > them. What I have right now is the text: > > Const DeleteReadOnly = TRUE > > Set objFSO = CreateObject("Scripting.FileSystemObject") > objFSO.DeleteFile("C:\Woo\*.txt"), DeleteReadOnly > > which I got from the Microsoft Scripting library. or possibly just invoke the command processor's internal DEL with its / S and /F switches (assuming it's not in a Win 9x variant OS), something like this ... with CreateObject("Wscript.Shell") .Run "%comspec% /c del C:\Woo\*.txt /S /F ", 0 end with An example of a 'pure script' recursive search is available at my website: http://members.cox.net/tglbatch/wsh/RecurseFolders.vbs.txt It just returns a list of all of the file names, but could be revised to match the file extension and then delete the matching files. I believe there is also an example in the MS Script Center examples for a recursive search using WMI, but that's really slow and the needed matching process complicated IMHO. The utility that MS provided in the command processor (DEL) is my personal choice for such a task. Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/ |
|||||||||||||||||||||||