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

Author Topic: Batch command to rename file with date help  (Read 2565 times)

0 Members and 1 Guest are viewing this topic.

trgrassi

    Topic Starter


    Newbie

    Batch command to rename file with date help
    « on: March 23, 2009, 10:59:04 AM »
    Was on this site and found code to rename a file using batch but I can not get it to work

    I have a file master.bak in folder T:\backup\master

    I would like to rename it with a current date

    rename master.bak master03232009.bak

    Here is my batch file

    @echo off
    T:
    cd\backup\master
    for /f "tokens=1-5 delims=/ " %%d in (%date%) do rename "master.bak" master%%e=%%f-%%g.bak

    exit

    the message I get is

    The system cannot find the file mon.

    Any idea on what is wrong?


    Thanks

    Tom

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Batch command to rename file with date help
    « Reply #1 on: March 23, 2009, 11:07:12 AM »
    try changing:
    Code: [Select]
    for /f "tokens=1-5 delims=/ " %%d in (%date%) do rename "master.bak" master%%e=%%f-%%g.bak

    to

    Code: [Select]
    for /f "tokens=1-5 delims=/ " %%d in ('date /t') do rename "master.bak" master%%e=%%f-%%g.bak
    I was trying to dereference Null Pointers before it was cool.

    trgrassi

      Topic Starter


      Newbie

      Re: Batch command to rename file with date help
      « Reply #2 on: March 23, 2009, 11:15:56 AM »
      thank you for your responce it worked like a champ

      thanks again

      tom