ajtsystems
IS-IT--Management
Hi
I am trying to copy files over 7 days old to an identical folder. My script so far creates a folder with a time stamp then searches through a folder structure for files older than 7 days and then copies them to the folder.
I really want to copy the file within the folder name to the destination as multiplke copies of the same file name exist in various folders at in the source folder and thi sis going to cause problems...
Here's my code so far
Set fso = CreateObject("Scripting.FileSystemObject")
StrMonth = Month(Date)
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
StrDay = Day(Date)
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
StrYear = Year(Date)
strFolderName = "C:\Scripts\" & "CL_" & strMonth & "-" & strDay & "-" & StrYear & "\"
Set objFolder = FSO.CreateFolder(strFolderName)
strDir = "c:\FSO"
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
'wscript.Echo aItem.Name
If DateDiff("d", aitem.DateLastModified, Now) > 7 Then
FSO.CopyFile aitem, strfoldername
End If
Next
For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next
End Sub
Any help would be good.
James
I am trying to copy files over 7 days old to an identical folder. My script so far creates a folder with a time stamp then searches through a folder structure for files older than 7 days and then copies them to the folder.
I really want to copy the file within the folder name to the destination as multiplke copies of the same file name exist in various folders at in the source folder and thi sis going to cause problems...
Here's my code so far
Set fso = CreateObject("Scripting.FileSystemObject")
StrMonth = Month(Date)
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
StrDay = Day(Date)
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
StrYear = Year(Date)
strFolderName = "C:\Scripts\" & "CL_" & strMonth & "-" & strDay & "-" & StrYear & "\"
Set objFolder = FSO.CreateFolder(strFolderName)
strDir = "c:\FSO"
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
'wscript.Echo aItem.Name
If DateDiff("d", aitem.DateLastModified, Now) > 7 Then
FSO.CopyFile aitem, strfoldername
End If
Next
For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next
End Sub
Any help would be good.
James