How to script a daily copy of files w/dt being name of archive folder


  1. Posts : 22
    windows 7 professional
       #1

    How to script a daily copy of files w/dt being name of archive folder


    Hello,

    I need to figure out a Windows 7 script to copy/archive files which are located in a specific folder. It needs to copy daily to an archive folder, with the script creating the archive folder as MM-DD-YY (being that day's date that is being archived) before it archives the files to that folder. The script will run at 9:00 pm every night, the time all work ceases.

    If anyone could help me with this script, I would appreciate it.
      My Computer


  2. Posts : 6,285
    Windows 10 Pro X64
       #2

    If the archive was going to be D:\MyArchives and the source was C:\Users\youruserid\SomeFolder:

    for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
    set "YYYY=%dt:~0,4%"
    set "MM=%dt:~4,2%"
    set "DD=%dt:~6,2%"

    set datestamp=%MM%-%DD%-%YYYY%
    echo datestamp: "%datestamp%"

    md D:\MyArchives\%datestamp%
    xcopy C:\Users\youruserid\SomeFolder\*.* D:\MyArchives\%datestamp%\ /s/h/r/i/k/e/y

    Enter xcopy /? from a Command Prompt to see what the parameters mean.

    Above found in a post by foxidrive here: Format date in Windows 7 batch job - Stack Overflow

      My Computer


  3. Posts : 22
    windows 7 professional
    Thread Starter
       #3

    Thank you! So I put this is some .bat file and trigger it through Task Scheduler?

    Sorry, I'm not sure exactly how to do this. I think I may know, but just not sure.
    Last edited by pglufkin; 29 May 2014 at 23:19.
      My Computer


  4. Posts : 6,285
    Windows 10 Pro X64
       #4

    Yes, put in a .bat file then schedule to run via Task Scheduler.

    Test the heck out of it first though.
    Last edited by Ztruker; 31 May 2014 at 20:16.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:30.
Find Us