Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file question  (Read 2845 times)

0 Members and 1 Guest are viewing this topic.

JOhnathan.Pierce

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    Batch file question
    « on: February 07, 2012, 03:13:24 PM »
    This is hard to word but I will do my best. What I am trying to do is make backups of backups basically. I have several files and folders in FOLDER1. What I want to do is make a batch file that will move my files and folders from FOLDER1 to FOLDER2. At the same time everytime I run this batch file I want it to create a folder in FOLDER2 with the month,day,year,time as the folder name because I am going to be running this batch everyday and I don't want it to overwrite my previous files. Is there anyway to do this.

    Thank you

    Salmon Trout

    • Guest
    Re: Batch file question
    « Reply #1 on: February 07, 2012, 03:43:52 PM »
    It would help to get the folder name right, (the date and time part) if you tell us your system's date format. You can do this by opening a command window and typing

    @ECHO %DATE% [hit ENTER]

    then

    @ECHO %TIME% [hit ENTER]

    and copying and pasting the results here.


    JOhnathan.Pierce

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: Batch file question
      « Reply #2 on: February 08, 2012, 07:11:03 AM »
      I actually got it figured out last night using this for future reference.

      @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
                      Set Month=%%A
                      Set Day=%%B
                      Set Year=%%C
      )

      REM @echo DAY = %Day%
      REM @echo Month = %Month%
      REM @echo Year = %Year%

      Thank you

      Raven19528



        Hopeful
      • Thanked: 30
        • Computer: Specs
        • Experience: Experienced
        • OS: Windows 7
        Re: Batch file question
        « Reply #3 on: February 08, 2012, 10:29:33 AM »
        You may be overcomplicating your file a little with the FOR command. This will accomplish the same thing (as it looks from the way you wrote your FOR command it looks like you have the NA date format.)

        Code: [Select]
        set day=%date:~7,2%
        set month=%date:~4,2%
        set year=%date:~10%

        Or even better, if you were looking for a same line solution:

        Code: [Select]
        md %date:~4,2%-%date:~7,2%-%date:~10%

        This doesn't help with the time variable, in which case I would say your best bet would be to use the FOR command to parse that out.
        "All things that are
        Are with more spirit chased than enjoy'd" -Shakespeare

        JOhnathan.Pierce

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: Batch file question
          « Reply #4 on: February 08, 2012, 10:31:27 AM »
          Ah I see. Very good point. Thank you. I wil use that instead.