strSourceDir = "C:\somepath" ' Set this to the directory you archive from
strDestDir = "C:\archive" ' Set this to the directory you archive to
intCutoffAge = 0 ' Set this to the age in days that you want to use for the cutoff
Set objFSO = CreateObject("Scripting.FileSystemObject")
CrawlTree strSourceDir
Sub CrawlTree(strSourceDir)
Dim objFolder, arrFolders, objFiles, Item, Item2
Set objFolder = objFSO.GetFolder(strSourceDir)
Set arrFolders = objFolder.SubFolders
Set objFiles = objFolder.Files
intPathLength = Len(strSourceDir)
intPathLength = intPathLength -2
strDestFolder = strDestDir & Right(strSourceDir,intPathLength)
Wscript.Echo "strDestFolder = " & strDestFolder
If Not objFSO.FolderExists(strDestFolder) Then
arrPath = Split(strDestFolder,"\")
strNewFolder = ""
For i = 0 to Ubound(arrPath)
Wscript.Echo arrPath(i)
strNewFolder = strNewFolder & arrPath(i) & "\"
Wscript.Echo strNewFolder
If Not objFSO.FolderExists(strNewFolder) Then
MakeFolder = objFSO.CreateFolder(strNewFolder)
Wscript.Echo strNewFolder & " created!"
Else
End If
Next
Else
End If
' Get all sub-folders in this folder
For Each Item In arrFolders
CrawlTree(item)
Next
Item2 = 0
'Scan through the files collection, find files older than cutoff age and moves them.
For Each Item2 in objFiles
Dim strAccessDate, strCreatedate, objFileName, intDaysOld
Set objFileName = objFSO.GetFile(Item2)
strAccessDate = objFileName.DateLastAccessed
intDaysOld = DateDiff("d", strAccessDate, Now)
If intDaysOld > intCutoffAge Then
Wscript.Echo Now & " -- " & objFileName.Path & " is " & intDaysOld & " days old."
strPathName = objFilename.Parentfolder
intPathLength = Len(strPathName)
intPathLength = intPathLength -2
strMovePath = strDestDir & Right(strPathName,intPathLength) & "\"
Wscript.Echo "objFilename.Path = " & objFilename.Path
Wscript.Echo strMovePath
objFileName.Move (strMovePath)
Wscript.Echo objFileName.Path & " was archived to " & strDestDir
Else
End If
Next
End Sub