VBS to delete file time in folder and sub folders

I'm looking to have a scheduled task that runs a VBS script (called from a bat file) that deletes PDF Files is a folder and it's sub folders. Thank you in advance for your help!!!!!
LVL 9
mystics7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rettiseertCommented:
If you are using a bat file why not to use a simple shell command? try this in the bat:

DEL C:\your_folder\*.pdf /S /Q /F
0
mystics7Author Commented:
this will also delete the pdfs from the sub folders?
0
mystics7Author Commented:
I also forgot to mention that this has to be done one files older than 30 days
0
Bill PrewCommented:
Why not just use this handy little free utility called DELAGE32

http://home.mnet-online.de/horst.muc/win/delage.htm
http://home.mnet-online.de/horst.muc/wbat32.htm

So a simple command like the following could do it for you:

delage32 c:\temp\*.pdf 31 /recurse

~bp
0
mystics7Author Commented:
here is the code if anyone needs it. This will delete specified files older than specified time and in subfolders
OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders
' Folder to delete files
strFolder = "C:\Test"
' Delete files from sub-folders?
includeSubfolders = true
' A comma separated list of file extensions
' Files with extensions provided in the list below will be deleted
strExtensionsToDelete = "pdf"
' Max File Age (in Days).  Files older than this will be deleted.
maxAge = 30

' ************************************************************

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders

wscript.echo "Finished"

sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
	DIM objFolder, objSubFolder, objFile
	DIM strExt

	set objFolder = objFSO.GetFolder(strDirectory)
	for each objFile in objFolder.Files
		for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
			if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
				IF objFile.DateLastModified < (Now - MaxAge) THEN
					wscript.echo "Deleting:" & objFile.Path & " | " & objFile.DateLastModified 
					objFile.Delete
					exit for
				END IF
			end if
		next
	next	
	if includeSubFolders = true then ' Recursive delete
		for each objSubFolder in objFolder.SubFolders
			DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
		next
	end if
end sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.