Batch file , change filename with system date and time infor


  1. Posts : 25
    Windows 7 Ultimate x64
       #1

    Batch file , change filename with system date and time infor


    I wrote a bat file, to change a file name, test.txt to testMonthDayYearTime.txt



    here is what i wrote:
    ren c:\example\test.txt test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt”



    But after running, the file name is test12182010 093012.txt, a space is between date and time. I don;t want the space. Anyone know what's wrong.
      My Computer


  2. Posts : 1,800
    Windows 7 Pro x64 SP1
       #2

    i used the same routine to set an environmental variable with your routine and it
    worked fine.

    set xx= test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt

    xx= test12192010150311.txt

    something tells me that your time display settings could be different than mine.

    I love batch files. :)

    Rich
      My Computer


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

    You're missing a double quote. Try this:

    ren test.txt "test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt"

    When I did it from a Command Prompt, I got: test12192010221526.txt

    Put it in a batch file and it still works, got: test12192010221739.txt
      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 05:36.
Find Us