We help IT Professionals succeed at work.

Move Files from Directory 1 to Directory 2 that have not been accessed in the last 30 days.

dutboy asked
Medium Priority
Last Modified: 2010-08-05

I hope you can help,  I need a script file to move files from one directory to another according to their last accessed date (not how old the files are).

Any files not accessed in the last 31days need to be moved to an archive folder.

This is on a windows 2000 server.

Sounds simple, but i stumped, Im quite new to this scripting business..

I hope you can help, and am sorry if this has been answered already,but i just cant find the solution.
Watch Question


Paste the following into a new text file, and save it as something with the extension of .vbs:

 Dim FSO, f, fld, fls, vOrigDir, vNewDir
 vOrigDir = "C:\foldername\"
 vNewDir = "C:\folder 2\"
 Set FSO = CreateObject("scripting.filesystemobject")
 Set fld = FSO.GetFolder(vOrigDir)
 Set fls = fld.Files
 For Each f In fls
  If f.DateLastAccessed < DateValue(CStr(Now)) - 30 Then f.Move vNewDir
 Set FSO = Nothing
 Set f = Nothing
 Set fld = Nothing
 Set fls = Nothing
 Set vOrigDir = Nothing
 Set vNewDir = Nothing

To run it, just double click the .vbs file.  You can also put this into windows scheduler to run it at specified intervals, if that helps you.  Please let us know if you need any help!

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks for such a  quick response and Matt it worked a treat.  Many thanks....

Glad to help!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.