2008年8月1日 星期五

自動在windows執行 每天刪除n天前的檔案

'自動化檔案維護管理程式
'天數
daysAgo = 7

'路徑
dirPath = "C:\\Temp2"

'副檔名
extName = ".txt"

';;;;;程式開始;;;;;
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 Right(fileName, Len(extName)) = extName And fileDate < dateBefore Then
fs.DeleteFile(dirPath & "\\" & fileName)
End If
Next

----------------------分格線-----------------------------------------
用途:自動在windows執行 每天刪除n天前的檔案
Step1:複製分格線以上ㄉ文字 貼在txt檔然後副檔名改成vbs
Step2:在windows的工作排程上使用該檔

後記:
上面是網路上找到ㄉ
試用後真ㄉ可以ㄝ!!
神奇ㄉVBS!!
有需要ㄉ可以參考看看!!
如果有直接使用command mode就可以完成ㄉ指令
也可以回覆我~~
3Q

沒有留言: