1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Creating directory names in a batch file

Discussion in 'Other PC Software' started by Grunty, 2004/08/17.

Thread Status:
Not open for further replies.
  1. 2004/08/17
    Grunty

    Grunty Inactive Thread Starter

    Joined:
    2002/11/07
    Messages:
    326
    Likes Received:
    0
    I have a batch file located on the desktop (XP Pro) that deletes all folders called C:\backup ", creates a new folder called "C:\backup" and copies files from around the hard-drive into it, ready for the user to write to a CD for backup purposes.

    I have done it this way to make it easy for the user to copy all her files to one place. She is comfortable with using a CD-writer but not much else.

    Can anyone tell me if it is possible to name the folder by date or something else, so that each backup she does can be stored on the same cd, as they are only about 20mb in total, or maybe there is a better way to accomplish the whole thing. It needs to be something as simple as clicking on a desktop icon and writing one folder to a cd.

    I have tried "md c:\%date% ", but it tells me the syntax in wrong.

    Thanks
     
  2. 2004/08/17
    PeteC

    PeteC SuperGeek Staff

    Joined:
    2002/05/10
    Messages:
    28,896
    Likes Received:
    389
    Take a look at the freeware version of SynchBack - I use it to mirror my data drive to a back up drive on an hourly basis, but it will do much more than that.

    Not being a 'dosser' I can't help you with syntax or batch files :D
     

  3. to hide this advert.

  4. 2004/08/17
    ReggieB

    ReggieB Inactive Alumni

    Joined:
    2004/05/12
    Messages:
    2,786
    Likes Received:
    2
    If you are in a batch file, you need to double up the percentage characters. So %%date%%

    However, I still don't think this will work as easily as that. I have an automated batch file at work that backs up a network folder and wanted to do the same as you. I ended up using GAWK to generate a date stamp. I will try and remember to post the bit of batch coding I used to do it tomorrow from work.

    However, if you want to try yourself, I think this page (AWK Scripts: Date and Time) is where I got the information I used to create my batch script.
     
  5. 2004/08/17
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    Try something like

    echo.|date|find "Current" >cu##ent.bat
    echo set date=%%4> current.bat
    call cu##ent.bat
    del cu??ent.bat > nul
    mkdir \%date%
     
  6. 2004/08/18
    ReggieB

    ReggieB Inactive Alumni

    Joined:
    2004/05/12
    Messages:
    2,786
    Likes Received:
    2
    I remember the problem with using %%date%% now. You end up with something along the lines of "Wed 18/08/04" (UK date format). Putting forward slashes into a file name creates an invalid file name.

    This is what I used:

    • set format=set datetime\075\045d\045m\045Y\045H\045M
    • gawk "BEGIN{Format = \ "%format%\ ";print strftime( Format, systime() )}" > }{.bat
    • call }{
    • del }{.bat

    If you put this in your batch file it will create a variable called %datetime%. This has the format ddmmyyyyHHMM. All numbers, with no punctuation. The advantage of including the hours and minutes, is that if the function is used more than once in a single day you get a new folder name for each instance. So:

    • mkdir foldername%datetime%

    Would create a folder called "foldername180820040131" at the time of writing.

    To do this you will need a Windows version of GAWK. You also need to have GAWK in your system path. For example by using something like this (at a command prompt - you should only have to do this once):

    • set path=%path%, "c:\program files\gawk\gawk306x\gnu\bin\ "
    There are a number of versions of GAWK ported for Windows. Here for example
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.