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

Posted on 2006-03-23
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.
Question by:dutboy
    LVL 6

    Expert Comment

    LVL 35

    Accepted Solution


    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!

    Author Comment

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

    Expert Comment

    Glad to help!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    This article will show, step by step, how to integrate R code into a R Sweave document
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now