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

Author Topic: Batch file to rename a file with date stamp in Win 7  (Read 9674 times)

0 Members and 1 Guest are viewing this topic.

anadolu

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Batch file to rename a file with date stamp in Win 7
    « on: December 08, 2010, 05:21:58 PM »
    Hello

    I used the info given in this site to rename a file using a batch file under Win 7. Batch file is as follows:

    echo Press to rename the old File.exe
    echo Renaming old File.exe if it exists...
    IF EXIST File.exe (
       for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename “File.exe" File-%%e-%%f-%%g.exe
    )

    Wit 7 complains that

    %%d was unexpected at this time.


    Where is the problem? Thank you.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch file to rename a file with date stamp in Win 7
    « Reply #1 on: December 08, 2010, 07:37:43 PM »
    Perhaps you could tell us what your think this part is going to do.
    Code: [Select]
    for /f "tokens=1-5 delims=/ " %%d in ("%date%") And then maybe we can tell why it won't do that.

    Salmon Trout

    • Guest
    Re: Batch file to rename a file with date stamp in Win 7
    « Reply #2 on: December 09, 2010, 12:14:15 AM »

    for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename “File.exe" File-%%e-%%f-%%g.exe
                                                              ^
                                                              |
                                                             here



    You used an opening quote before the file name "File.exe" when you should have used an ordinary standard double quote. Check for others. Also please give your local date format.

    Please ignore Geek-9pm.






    Salmon Trout

    • Guest
    Re: Batch file to rename a file with date stamp in Win 7
    « Reply #3 on: December 09, 2010, 12:18:51 AM »
    Perhaps you could tell us what your think this part is going to do.

    It's obvious what he thinks that part is going to do. Split up the date string into 5 tokens delimited by the / character and the space character. Which it actually does. What is the purpose of your participation in this thread?



    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch file to rename a file with date stamp in Win 7
    « Reply #4 on: December 09, 2010, 02:50:35 AM »
    Quote
    What is the purpose of your participation in this thread?
    To show my ignorance.  :-[

    Salmon Trout

    • Guest
    Re: Batch file to rename a file with date stamp in Win 7
    « Reply #5 on: December 09, 2010, 04:57:19 AM »
    To show my ignorance.  :-[

    Now I feel guilty  :-[


    anadolu

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Batch file to rename a file with date stamp in Win 7
      « Reply #6 on: December 09, 2010, 06:54:54 AM »
      Hello all,

           Thank you for your responses. But no solution. I was just following teh article in this website:http://www.computerhope.com/issues/ch000987.htm

           which allows one to rename a file with date stamp: e.g. File.exe as renamed as File-12-23-2001.exe where the date info comes from the OS.

           You can copy this line from the article and try it on a file. You will get the error.

           I did not understand your comment "salmon trout" that I use a wrong kind of "". Could you be more specific please?

      Salmon Trout

      • Guest
      Re: Batch file to rename a file with date stamp in Win 7
      « Reply #7 on: December 09, 2010, 07:59:37 AM »
           I did not understand your comment "salmon trout" that I use a wrong kind of "". Could you be more specific please?

      Try looking closely at your post and my answer.

      This is wrong “
      This is right "


      Salmon Trout

      • Guest
      Re: Batch file to rename a file with date stamp in Win 7
      « Reply #8 on: December 09, 2010, 10:14:05 AM »
      Further clarification

      1. This shows the code in the Computer hope article

      The quote before hope.txt is correct.



      2. This shows the code in your post. The quote immediately before File.exe is the wrong kind.




      Also, the article is misleadingly inaccurate:

      Quote
      When %date% is used in a batch file it displays the date in the following format: Sun 09/02/2007

      The date is not displayed like that in most countries outside the USA.