thread329-1485856
I have the following working really well thanks to Councilk on thread but I need to remove one month.
e.g.
Date Created: 16/06/2011
New Folder: 201105
Flag = "0"
FolderPath = "C:\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.Getfolder(FolderPath)
Set colFiles = objFolder.Files
Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = "C:\"
For Each objFile In colFiles
MonthNumber = Right(("0" & Month(objFile.DateCreated)), _
((Year(objFile.Datecreated))))
YearNumber = Right(("" & Year(objFile.DateCreated)), _
(("0" & Year(objFile.DateCreated))))
Folder = YearNumber & MonthNumber
'Checks to see if the folder is already created and if not creates it
If objFSO.FolderExists(Folder) = False Then objFSO.CreateFolder Folder
'Checks to see if the file already exists in the folder and if it does deletes it before copying the new version of the file over
If objFSO.FileExists(Folder & objFile.Name) = True Then objFSO.DeleteFile Folder & objFile.Name, True
'Moves the file to the new folder
objFSO.CopyFile objFile.Path , Folder & "\" & objFile.Name
Next
'Deletes the *.csv files in the FolderPath
Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile("C:\*.csv")
I have the following working really well thanks to Councilk on thread but I need to remove one month.
e.g.
Date Created: 16/06/2011
New Folder: 201105
Flag = "0"
FolderPath = "C:\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.Getfolder(FolderPath)
Set colFiles = objFolder.Files
Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = "C:\"
For Each objFile In colFiles
MonthNumber = Right(("0" & Month(objFile.DateCreated)), _
((Year(objFile.Datecreated))))
YearNumber = Right(("" & Year(objFile.DateCreated)), _
(("0" & Year(objFile.DateCreated))))
Folder = YearNumber & MonthNumber
'Checks to see if the folder is already created and if not creates it
If objFSO.FolderExists(Folder) = False Then objFSO.CreateFolder Folder
'Checks to see if the file already exists in the folder and if it does deletes it before copying the new version of the file over
If objFSO.FileExists(Folder & objFile.Name) = True Then objFSO.DeleteFile Folder & objFile.Name, True
'Moves the file to the new folder
objFSO.CopyFile objFile.Path , Folder & "\" & objFile.Name
Next
'Deletes the *.csv files in the FolderPath
Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile("C:\*.csv")