#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Canada
    Posts
    368
    Rep Power
    12

    Batch file creating folder name from date command?


    I am trying to run a batch file that backs up directories into a new directory that has the current date in the form YYYY-MM-DD. I got it to work on one machine (running xp pro) but not on the machine I need it to run on (also running xp pro). I do not know cmd line scripting at all, I borrowed the following from these forums, if I recall correctly:
    __________________________
    @echo off
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
    FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
    FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
    FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
    SET date=%yyyy%-%mm%-%dd%
    md C:\tempbackup\%date%
    xcopy /e C:\TEMP\*.* C:\tempbackup\%date%
    pause
    _____________________

    The above creates a directory called:
    c:\tempbackup\on.-05-\
    but it is supposed to create
    c:\tempbackup\2006-05-17\

    suggestions?
    thanks
    mr_fitz
    __________
    Don't worry, I haven't given up my day job.
  2. #2
  3. Providing fuel for space ships
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2004
    Location
    nr Edinburgh, Scotland
    Posts
    14,382
    Rep Power
    3848
    Try using this code
    Code:
    @echo off
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
    FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
    FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
    FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
    SET date="%date:~0,2%-%date:~3,2%-%date:~6,6%"
    md C:\tempbackup\%date%
    xcopy /e C:\TEMP\*.* C:\tempbackup\%date%
    pause
    This better for you ?
    The No Ma'am commandments:

    1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
    2.) It is wrong to be French
    3.) It is O.K. to put all bad people in a giant meat grinder
    4.) Lawyers, see rule 3
    5.) It is O.K. to drive a gas guzzler if it helps you get babes
    6.) Everyone should car pool but me
    7.) Bring back the word 'stewardesses'
    8.) Synchronized swimming is not a sport
    9.) Mud wrestling is a sport
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    You solved my problem


    Originally Posted by mr_fitz
    I am trying to run a batch file that backs up directories into a new directory that has the current date in the form YYYY-MM-DD. I got it to work on one machine (running xp pro) but not on the machine I need it to run on (also running xp pro). I do not know cmd line scripting at all, I borrowed the following from these forums, if I recall correctly:
    __________________________
    @echo off
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
    FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
    FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
    FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
    SET date=%yyyy%-%mm%-%dd%
    md C:\tempbackup\%date%
    xcopy /e C:\TEMP\*.* C:\tempbackup\%date%
    pause
    _____________________

    The above creates a directory called:
    c:\tempbackup\on.-05-\
    but it is supposed to create
    c:\tempbackup\2006-05-17\

    suggestions?
    thanks
    After a little experimentation (and trying aitken325i's change), I believe the problem is that the two computers provide a different response to the date/T command. For my computer (and probably the first one you tested) the response is:
    Sat 07/17/2010

    aitken325i led me to a much abriged batch file that worked with the date format above.
    @echo off
    SET date="%date:~10,4%-%date:~4,2%-%date:~7,2%"
    md C:\tempbackup\%date%
    xcopy /e C:\TEMP\*.* C:\tempbackup\%date%
    pause

    The resulting folder is C:\tempbackup\2010-07-17 which keeps the backups in a nice date order.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Move files into new folder that has a name based on the "date modified" attribute


    I have a folder called Pictures. Under that folder are a bunch of sub-folders named various peoples names. Inside those folders are any number of pictures taken of them on various dates. I need to move those pictures into sub-folders that are named based on the date modified attribute of the file being copied. As an example, I would like to copy:

    c:\pictures\tim\test.jpg

    To:
    c:\pictures\tim\2011-3-10\test.jpg

    The "2011-3-10" folder should be automatically created using the date modified attribute. I need to do this for hundreds of directories and thousands of pictures.

    Does anyone have any suggestions on how I can script this?

    Thanks.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Batch File Rename Utility


    Here is an excellent tool to batch files rename easily “KrojamSoft BatchRenameFiles tool"
    BatchRenameFiles.org

IMN logo majestic logo threadwatch logo seochat tools logo