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

How do I include multiple paths to this script?

Status
Not open for further replies.

Daniel_Son

Programmer
Dec 30, 2021
1
0
0
US
I need to add multiple paths to the scrip below. Please assist!

OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders

' ************************************************************
' Setup
' ************************************************************

' Folder to delete files
' I want to add multiple paths to this script
strFolder = "C:\Users\Desktop\Testing", "C:\Users\Desktop\Testing_2", "C:\Users\Desktop\Testing_3"
' 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 = 7

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

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders

wscript.echo "PDFs are deleted"

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

 
The code you posted is unformatted and so difficult to read. Please post your programming code between the tags:
[pre]
Code:
[/pre] ... [pre]
[/pre]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top