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

Author Topic: Need advice in appending current date to the file name  (Read 7210 times)

0 Members and 1 Guest are viewing this topic.

narasimha.sathi

  • Guest
Need advice in appending current date to the file name
« on: September 29, 2011, 09:44:06 AM »
Hello All,

I am trying to append the current date to the end of the file name and I am using bat file script to do it. For example, I have the file 1.txt and when I use the script, the file name should be renamed as 1_29_09_2011.txt.

The script works good in Windows 7 and Windows 2003 Enterprise x64 Edition SP2.

However, for Windows 2003 Standard Edition SP2, the output I am receiving is 1_09-2011-.txt

The below are the contents of the bat file script:

for %%a in ("1.txt") do (
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "%%a" "%%~Na_%%e-%%f-%%g%%~Xa"
)

The OS version where I have issue is: Windows 2003 Standard Edition SP2.

Please help me in this regard. Thanks in advance.

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Need advice in appending current date to the file name
« Reply #1 on: September 30, 2011, 08:46:44 PM »
On the system that is acting up, have you verified the output structure of %date% such as running @echo. %date% from command shell to make sure its the correct structure format, same order as the other systems that work correctly. To me it looks like your system that is acting up for this batch is not the same %date% output structure?

Your example of what you should get shows DDMMYYYY and your undesired output is showing MMYYYY missing the DD ( Day value)