Announcement

Collapse
No announcement yet.

Batch File to Rename Files as Date

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch File to Rename Files as Date

    Hi Everyone,

    Just a simple question. Im running NTBackup on a machine which outputs to a file called Daily.bkf. Now i just need a batch file to rename the file as the current date.

    TIA

    Matty

  • #2
    Re: Batch File to Rename Files as Date

    OK, a bit of googling around and combining bits a pieces of other scripts i found my answer.


    Just incase anyone else wants to know

    Code:
    @echo off
    for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "Daily.bkf" %%e-%%f-%%g.bkf
    Last edited by Pulsen; 15th March 2008, 09:02.

    Comment


    • #3
      Re: Batch File to Rename Files as Date

      Well done on working it out and thanks for posting back here and sharing your work. Your community spirit is appreciated so have some points as a Thank You!

      POX!! I have inadvertantly removed Reputation Point. I shall add them back on another post. I have posted this so you don't get confused as to what is happening to your points and why they are being applied to obscure posts. Sorry.
      Last edited by biggles77; 15th March 2008, 14:27. Reason: Correct a points screwup by me.
      1 1 was a racehorse.
      2 2 was 1 2.
      1 1 1 1 race 1 day,
      2 2 1 1 2

      Comment


      • #4
        Re: Batch File to Rename Files as Date

        The format of the variable %Date% (or the command Date /T ) is different in different languages. The format could be dd mm yyyy or mm dd yyyy, also the separaters are different in localized OSs.

        Have a look here how the datestamp is retrieved in different ways in these batches;
        - http://forums.petri.com/showpost.php...02&postcount=6 (using 'date /t')
        - http://forums.petri.com/showpost.php...57&postcount=2 (using 'date /t', and call subroutine)
        - http://forums.petri.com/showpost.php...24&postcount=6 (Use 'WMIC')

        The first 2 batchsamples use the the same principle, that was first showed and explaned here by Michael Jerkovic:
        http://groups.google.com/group/alt.m...eddc47adc018fb

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Batch File to Rename Files as Date

          Had a similar problem where I just wanted my script to spit out it's results into multiple text files labeled by date 080402.txt etc etc. Ended up using:

          %date:~12,2%%date:~4,2%%date:~7,2%.txt

          Hope this helps someone else.

          Comment


          • #6
            Re: Batch File to Rename Files as Date

            Originally posted by f21 View Post
            Had a similar problem where I just wanted my script to spit out it's results into multiple text files labeled by date 080402.txt etc etc. Ended up using:

            %date:~12,2%%date:~4,2%%date:~7,2%.txt

            Hope this helps someone else.
            Thanks for the update f21.


            For my OS's localized setting (Dutch), your solution would be like:
            Code:
            @echo. jj- %date:~11,2% , mm- %date:~6,2% , dd- %date:~3,2%
            
            ::OR
            
            @echo. jjjj- %date:~-4% , mm- %date:~6,2% , dd- %date:~3,2%
            
            
            :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
            :: Specify substrings for an expansion;
            ::  <www.dostips.com/DtTipsStringManipulation.php>
            :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

            note: The solutions I linked-to in my previous post there is tried to tackle most issues that might occour when using the same script on different computers configured w/ different regional settings (date formats).

            \Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Batch File to Rename Files as Date

              Thanks for the catch Rems. My script had broken just two days ago and I had no idea why at first until I read your reply. I hadn't considered the regional issue. Somehow my Regional and Language options had changed my short date format from m/d/yyyy to mm/dd/yyyy. The echo from date looks identical apart from the day of week missing (Thu etc).

              I also didn't know that you could change the date separator in this options menu. Makes for an even easier and dirtier fix if you're only working on one computer. Would've saved me a lot of time

              Comment

              Working...
              X