如何修改以下脚本以避免硬编码位置、日期戳和扩展名,并将这些详细信息指定为命令提示符中的输入变量,例如“cscript del.vbs d:\temp 16/08/2013 jpg” .
OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders
' ************************************************************
' Setup
' ************************************************************
' Folder to delete files
strFolder = "d:\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 = "jpg"
' Max File Age (in Days). Files older than this will be deleted.
maxAge = 1
' ************************************************************
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