【发布时间】:2012-03-11 08:35:06
【问题描述】:
我希望遍历共享上的文件夹,如果文件夹或子文件夹包含超过 90 天的文件,则复制整个结构。 (如果文件夹包含所述旧文件,则移动早于所述天数的文件)
我在网上找到了一个脚本,我将其更改为实际正确使用 DateAdd 函数,它似乎可以移动文件但它不会复制结构。
示例。
2 共享包含文件的位置(这不是确切的结构,只是一个示例)
Source
1. \\Share1\folder
2. \Folder\Files
3. \Folder\Files
4. \Folder
1. \\Share2\folder
2. \Folder\Files
3. \Folder\Files
4. \Folder
Destination
1. \\Share2\folder
2. \Folder\Files
3. \Folder\Files
4. \Folder
1. \\Share2\folder
2. \Folder\Files
3. \Folder\Files
4. \Folder
Dim objFSO, ofolder, objStream
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
set outfile = fso.createtextfile("Move-Result.txt",true)
SPath = "Y:\test"
Sdest = "Y:\Archive\"
ShowSubfolders FSO.GetFolder(spath)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
CheckFolder(subfolder)
ShowSubFolders Subfolder
Next
End Sub
'CheckFolder(objFSO.getFolder(SPath))
Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile
Const OverwriteExisting = TRUE
currDate = Date
dtmDate = DateAdd("d",-90,Now)
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
FileName = objFile
'WScript.Echo FileName
'strDate = ConvDate(objFile.DateCreated)
strDate = ConvDate(objFile.DateLastModified)
If strDate < strTargetDate Then
objFSO.MoveFile FileName, Sdest
outfile.writeline Filename
End If
Next
End Sub
Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function
【问题讨论】:
标签: windows scripting vbscript administration