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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archiving Files and Folders

Status
Not open for further replies.

johnwon

Technical User
May 18, 2012
1
US
I have tried building several scripts unsucessfully and need some help scripting this one... I am trying to achieve the following:
1. Move all files that are older than 01/01/2011 and were created on the first of the month to C:\Archive from D:\Reports.
2. Delete all files that were not moved and were created before 01/01/2011 in D:\Reports.

When I move these files, I need to preserve the folder structure, because many of the files have the same name but are in folders named differently and the folder structure goes about 4 levels deep.

There are hundreds of folders containing thousands of files, so it's going to be a process. Thanks in advance for any suggestions you may have.
 
Think about what steps are needed to accomplish this. Write then down and create functions for each. When you have a working set of functions, consolidate them into on for efficiency sake. The program should be no more than 20 lines.

Q: How do we discover the files?
A: Write a recursive function to find the files in a given directory older than 01/01/2011 (Search this forum, there are plenty of examples). Additionally, if a file is found to be old, check the day of the file to see if it was created on the first of the month ([tt]if (day(file.DateCreated) = 1) then true[/tt]). If the condition is false, delete the file (this meets your 2nd step). Return a list of all files that pass these conditions.

Q: How do we move the files?
A: Iterate through the the list of files that the previous function returned and move each one using the .move method of the File.FileSystemObject (FSO). Simply replace "D:\Reports" with "C:\Archive" to conserve folder structure (pseudo)
Code:
for each file in list
   destination = replace(file.Path, "D:\Reports", "C:\Archive")
   file.move destination
next

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top