2010年1月7日 星期四

以vbs自動維護過期檔案

'--以vbs自動維護過期檔案
'--code by http://popo-it.blogspot.com/
'--以下存成.vbs即可
'---------------------------------------

'--程式開始

'--設定天數
days = 30
'--Source路徑
dirPath_from = "E:\\A"

'--Dest路徑
dirPath_to = "E:\\B"

'副檔名
ext_name = ".txt"

Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set w = WScript.CreateObject("WScript.Shell")
Set f = objFSO.GetFolder(dirPath_from)
Set fc = f.Files

pastdate = Now() - days
For Each f1 in fc

fileName = f1.Name
fileDate = f1.DateLastModified
If Right(fileName, Len(ext_name)) = ext_name And fileDate < pastdate Then
'--移到別的目錄
'----若目的地已有,刪
If objFSO.FileExists(dirPath_to & "\\" & fileName) Then
Set objFileCopy = objFSO.GetFile(dirPath_to & "\\" & fileName)
objFileCopy.Delete
End IF
Set objFileCopy = objFSO.GetFile(dirPath_from & "\\" & fileName)
objFileCopy.Move (dirPath_to & "\\" & fileName)
End If
Next


'--子目錄
'Set fc = f.SubFolders
'For Each f1 in fc
' s = s & f1.name
'Next

msgbox "OK"

沒有留言:

張貼留言