Mar 25, 2008

VBScript - 刪除兩天以前的檔案

'Delete 2 days ago files

'date
daysAgo = 2

'folder path
dirPath = "D:\\backup\archlog"

Set fs = CreateObject("Scripting.FileSystemObject")
Set w = WScript.CreateObject("WScript.Shell")

Set f = fs.GetFolder(dirPath)
Set fc = f.Files

dateBefore = Now() - daysAgo

For Each ff in fc
fileName = ff.Name
fileDate = ff.DateLastModified

If fileDate < dateBefore Then
fs.DeleteFile(dirPath & "\\" & fileName)
End If
Next

0 意見: