正在查找VBScript以将3年以上的文件移动到新文件夹,同时保持文件夹结构

正在查找VBScript以将3年以上的文件移动到新文件夹,同时保持文件夹结构,vbscript,Vbscript,我希望将文件从文件服务器移动到磁带机以节省空间。我需要一个脚本,将允许我移动所有的文件被访问3年前或以后,而仍然保持其文件夹结构 例如,d:\share\it\test.txt->d:\archive\share\it\test.txt,假设test.txt文件已经三年没有被访问过 然后,我将在此文件夹上运行磁带备份 我有一些我一直在使用的脚本。我使用过的最有效的方法是这个,但tt不会在测试文件夹中重新创建文件结构: Dim objFSO, ofolder, objStream, strSafe

我希望将文件从文件服务器移动到磁带机以节省空间。我需要一个脚本,将允许我移动所有的文件被访问3年前或以后,而仍然保持其文件夹结构

例如,d:\share\it\test.txt->d:\archive\share\it\test.txt,假设test.txt文件已经三年没有被访问过

然后,我将在此文件夹上运行磁带备份

我有一些我一直在使用的脚本。我使用过的最有效的方法是这个,但tt不会在测试文件夹中重新创建文件结构:

Dim objFSO, ofolder, objStream, strSafeDate, strSafeTime, strDateTime, strLogFileName

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")

strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

Set strDateTime equal to a string representation of the current date and time, for use as part of a valid Windows filename

strDateTime = strSafeDate & "-" & strSafeTime

'Assemble the path and filename
strLogFileName ="Move File " & strDateTime & ".txt"
set outfile = fso.createtextfile(strLogFileName,true)
SPath = "I:\Tech Docs"
Sdest = "I:\Test\"

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",-0,Now)
    strTargetDate = ConvDate(dtmDate)
    For Each objFile In objCurrentFolder.Files
        FileName = objFile
        'WScript.Echo FileName
        'strDate = ConvDate(objFile.DateCreated)
        strDate = ConvDate(objFile.DateLastAccessed)
        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
    `
Dim objFSO,of文件夹,objStream,strSafeDate,strSafeTime,strDateTime,strLogFileName
设置objShell=CreateObject(“WScript.Shell”)
设置objFSO=CreateObject(“scripting.filesystemobject”)
Set objNet=CreateObject(“WScript.NetWork”)
设置FSO=CreateObject(“Scripting.FileSystemObject”)
strSafeDate=DatePart(“yyyy”,Date)和Right(“0”和DatePart(“m”,Date),2)和Right(“0”和DatePart(“d”,Date),2)
strSafeTime=Right(“0”和小时(现在),2)和Right(“0”和分钟(现在),2)和Right(“0”和秒(现在),2)
将strDateTime设置为当前日期和时间的字符串表示形式,以用作有效Windows文件名的一部分
strDateTime=strSafeDate&“-”和strSafeTime
'组装路径和文件名
strLogFileName=“移动文件”&strDateTime&“.txt”
set outfile=fso.createtextfile(strLogFileName,true)
SPath=“I:\Tech Docs”
Sdest=“I:\Test\”
ShowSubfolders FSO.GetFolder(spath)
子文件夹(文件夹)
对于Folder.SubFolders中的每个子文件夹
检查文件夹(子文件夹)
显示子文件夹子文件夹
下一个
端接头
'检查文件夹(objFSO.getFolder(SPath))
子检查文件夹(objCurrentFolder)
Dim strTempL、strTempR、STREARCH、STREARCH、objNewFolder、objFile
Const OverwriteExisting=TRUE
currDate=日期
dtmDate=DateAdd(“d”、-0,现在)
strTargetDate=ConvDate(dtmDate)
对于objCurrentFolder.Files中的每个objFile
FileName=objFile
'WScript.Echo文件名
'strDate=ConvDate(objFile.DateCreated)
strDate=ConvDate(objFile.dateLastAccess)
如果strDate
Dim objFSO,of older,objStream,strSafeDate,strSafeTime,strDateTime,strLogFileName
设置objShell=CreateObject(“WScript.Shell”)
设置objFSO=CreateObject(“scripting.filesystemobject”)
Set objNet=CreateObject(“WScript.NetWork”)
设置FSO=CreateObject(“Scripting.FileSystemObject”)
strSafeDate=DatePart(“yyyy”,Date)和Right(“0”和DatePart(“m”,Date),2)和Right(“0”和DatePart(“d”,Date),2)
strSafeTime=Right(“0”和小时(现在),2)和Right(“0”和分钟(现在),2)和Right(“0”和秒(现在),2)
将strDateTime设置为当前日期和时间的字符串表示形式,以用作有效Windows文件名的一部分
strDateTime=strSafeDate&“-”和strSafeTime
'组装路径和文件名
strLogFileName=“移动文件”&strDateTime&“.txt”
set outfile=fso.createtextfile(strLogFileName,true)
SPath=“I:\Tech Docs\”
Sdest=“I:\Test\”
ShowSubfolders FSO.GetFolder(spath)
子文件夹(文件夹)
检查文件夹
对于Folder.SubFolders中的每个子文件夹
显示子文件夹子文件夹
下一个
端接头
'检查文件夹(objFSO.getFolder(SPath))
子检查文件夹(objCurrentFolder)
Dim strTempL、strTempR、STREARCH、STREARCH、objNewFolder、objFile
Const OverwriteExisting=TRUE
currDate=日期
dtmDate=DateAdd(“d”、-0,现在)
strTargetDate=ConvDate(dtmDate)
对于objCurrentFolder.Files中的每个objFile
“既然我们想保留这条路,我们就必须重建它
sAbsPath=objFile.Path
'在路径中交换源和目标,并删除文件名
“从小路上。
sNewPath=Replace(Replace(sAbsPath,sPath,Sdest),“\”&objFile.Name,”)
'在这里,如果路径不存在于
'目的地与我们的新子“MakeDir”
MakeDir sNewPath
FileName=objFile
'WScript.Echo文件名
'strDate=ConvDate(objFile.DateCreated)
strDate=ConvDate(objFile.dateLastAccess)
如果strDate=
你在问什么?如果你有一个脚本,它是有效的。。。到底是什么问题?这个脚本和我的一样接近。它不会在测试文件夹中重新创建文件结构。我想我应该说“这个脚本和我得到的一样接近”。基本上我需要弄清楚如何让脚本在测试中重新创建文件路径
Dim objFSO, ofolder, objStream, strSafeDate, strSafeTime, strDateTime, strLogFileName

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")

strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

Set strDateTime equal to a string representation of the current date and time, for use as part of a valid Windows filename

strDateTime = strSafeDate & "-" & strSafeTime

'Assemble the path and filename
strLogFileName ="Move File " & strDateTime & ".txt"
set outfile = fso.createtextfile(strLogFileName,true)
SPath = "I:\Tech Docs\"
Sdest = "I:\Test\"

ShowSubfolders FSO.GetFolder(spath)

Sub ShowSubFolders(Folder)
    CheckFolder Folder
    For Each Subfolder in Folder.SubFolders
        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",-0,Now)
    strTargetDate = ConvDate(dtmDate)
    For Each objFile In objCurrentFolder.Files

        'Since we want to preserve the path, we've got to reconstruct it
        sAbsPath = objFile.Path
        'Swap source and destination in the path, and strip the file name
        'from the path.
        sNewPath = Replace(Replace(sAbsPath,sPath,Sdest),"\" & objFile.Name,"")
        'Here we reconstruct the path if it doesn't exist in the
        'destination with our new Sub "MakeDir"
        MakeDir sNewPath

        FileName = objFile
        'WScript.Echo FileName
        'strDate = ConvDate(objFile.DateCreated)
        strDate = ConvDate(objFile.DateLastAccessed)
        If strDate =< strTargetDate Then
            'Finally we copy the file to the sNewPath
            objFSO.MoveFile FileName, sNewPath & "\"
            outfile.writeline Filename
        End If
    Next
End Sub

Sub MakeDir(strPath)
    On Error Resume Next
        strParentPath = objFSO.GetParentFolderName(strPath)

        If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
        If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder strPath
    On Error Goto 0 
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