Trying to write a script to move files with last month's date in the filename to an archive folder that exists in the same folder. For instance:
C:\_Temp_Delete\Daily Reports\Report 1 folder --> this is where the file initially resides
C:\_Temp_Delete\Daily Reports\Report 1 folder\Archive-2013\2013-01 --> this is where i want to put it
I'm getting a Path not Found error on the MoveFile command:
FSO.MoveFile Subfolder & "\" & File.Name, ArchDir
If I change that line like so, I get a File Already Exists error (but it doesn't exist in the archive folder):
FSO.MoveFile Subfolder & "\" & File.Name, Subfolder & "\" & ArchDir
Help would be greatly appreciated.
C:\_Temp_Delete\Daily Reports\Report 1 folder --> this is where the file initially resides
C:\_Temp_Delete\Daily Reports\Report 1 folder\Archive-2013\2013-01 --> this is where i want to put it
I'm getting a Path not Found error on the MoveFile command:
FSO.MoveFile Subfolder & "\" & File.Name, ArchDir
If I change that line like so, I get a File Already Exists error (but it doesn't exist in the archive folder):
FSO.MoveFile Subfolder & "\" & File.Name, Subfolder & "\" & ArchDir
Help would be greatly appreciated.
Code:
Dim Folder
Dim File
'MainPath = "\\cpo\shares\common\daily reports"
MainPath = "C:\_Temp_Delete\Daily Reports"
ArchDir = "Archive-" & Year(Date) & "\" & Year(Date) & "-" & Right("0" & Month(Date)-1,2)
'msgbox ArchDir
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder(MainPath)
For Each Subfolder in Folder.Subfolders
If Subfolder.ParentFolder <> "Archive-" & Year(Date) Then
For Each File in Subfolder.Files
If (inStr(File.Name, Year(Date) & Right("0" & Month(Date)-1,2))) Then
' msgbox Subfolder & "\" & File.Name & ", " & ArchDir
FSO.MoveFile Subfolder & "\" & File.Name, ArchDir
End If
Next
End If
Next