Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script for selective file moves

Status
Not open for further replies.
Jul 24, 2007
9
US
Here is what I am doing:

1 - Enumerate all subfolders in "C:\DirectMail" and if the folder does not exist in "C:\Archive" then create it

2 - Enumerate all files in all subfolders of "C:\DirectMail" and if the file is older than 14 days then move it to its respective folder in "C:\Archive"

Example: Move these files to their respective folders
C:\DirectMail\ATT\NEW_File.txt
C:\DirectMail\Home\Home.txt

Move to if > 14 days

C:\Archive\ATT\NEW_File.txt
C:\DirectMail\Home\Home.txt

Here is the first part of the script that I have:

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder("C:\DirectMail")
Set colSubfolders = objFolder.Subfolders
strDestFolder = "C:\Archive"
strSourceFolder = "C:\DirectMail"

For Each objSubfolder in colSubfolders
If Not objFSO.FolderExists(strDestFolder & "\" & objSubFolder.Name) Then
objFSO.CreateFolder(StrDestFolder & "\" & objSubFolder.Name)

End If

Next

I just need to be able to go through all the files in C:\DirectMail\*all subfolders* and move the ones that are older than 14 days.

I am almost there, but I have trouble with variables

Any help would be greatly appreciated

Thanks

Jake

 
A starting point:
For Each objSubfolder In objFolder.Subfolders
If Not objFSO.FolderExists(strDestFolder & "\" & objSubFolder.Name) Then
objFSO.CreateFolder(StrDestFolder & "\" & objSubFolder.Name)
End If
For Each objFile In objSubfolder.Files
If objFile.DateLastModified < Now-14 Then
objFile.Move StrDestFolder & "\" & objSubFolder.Name & "\"
End If
Next
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I am an idiot, that is sort of the same code that I had before and it was doing the same thing...NOTHING. No errors, no file moves...nada.

Well, I decided after it didnt work to look at the files and none of the files were being moved because the dates were today! DUH!!!!

Thansk for the help!!!!

Jake
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top