

InterviewSolution
Saved Bookmarks
1. |
Solve : Need advice in appending current date to the file name? |
Answer» <html><body><p>Hello All,<br/><br/>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.<br/><br/>The script works good in Windows 7 and Windows <a href="https://interviewquestions.tuteehub.com/tag/2003-243754" style="font-weight:bold;" target="_blank" title="Click to know more about 2003">2003</a> Enterprise x64 Edition SP2.<br/><br/>However, for Windows 2003 Standard Edition SP2, the output I am receiving is 1_09-2011-.txt<br/><br/>The below are the contents of the bat file script:<br/><br/>for %%a in ("1.txt") do (<br/>for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "%%a" "%%~Na_%%e-%%f-%%g%%~Xa"<br/>)<br/><br/>The OS version where I have issue is: Windows 2003 Standard Edition SP2.<br/><br/>Please <a href="https://interviewquestions.tuteehub.com/tag/help-239643" style="font-weight:bold;" target="_blank" title="Click to know more about HELP">HELP</a> me in this regard. <a href="https://interviewquestions.tuteehub.com/tag/thanks-665909" style="font-weight:bold;" target="_blank" title="Click to know more about THANKS">THANKS</a> in advance.<br/>On the system that is acting up, have you <a href="https://interviewquestions.tuteehub.com/tag/verified-2320336" style="font-weight:bold;" target="_blank" title="Click to know more about VERIFIED">VERIFIED</a> 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 <a href="https://interviewquestions.tuteehub.com/tag/systems-239492" style="font-weight:bold;" target="_blank" title="Click to know more about SYSTEMS">SYSTEMS</a> that work correctly. To me it looks like your system that is acting up for this batch is not the same %date% output structure?<br/><br/>Your example of what you should get shows DDMMYYYY and your undesired output is showing MMYYYY missing the DD ( Day value)</p></body></html> | |