Saved Bookmarks
| 1. |
Solve : Rename a file using Batch File Commands? |
|
Answer» HELLO Gurus, I am able to move and delete files from a folder. I want to rename the file (append date in YYYYMMDD format) while moving into another folder. Is it possible??? Eg. File name - Abc.xls Rename to Abc20050527.xls Thanks in advance Sudheer Rao:(it isn't possibleCode: [Select] for /F "tokens=1-4 delims=/ " %%a in ("%date%") do ( set mm=%%b set dd= %%c set yyyy=%%d ) move path\filename.ext path\filename%yyyy%%mm%%dd%.ext The code you actually use depends on the OS and your regional settings. Hope this helps. Hey all... Is it possible to have both date and time renamed into a file...? Thanks in advance Yes. When faced with a challenge LIKE this, it's best to echo a variable to the command line and work backwards from the result. Code: [Select] for /f "tokens=1-4 delims=/ " %%a in ("%date%") do ( set mo=%%b set dd= %%c set yyyy=%%d ) for /f "tokens=1-4 delims=:. " %%a in ("%time%") do ( set hh=%%a set mm=%%b set ss=%%c set ms=%%d ) ren path\filename.ext "path\filename%yyyy%%mo%%dd%%hh%%mm%%ss%%ms%.ext" Note: On some configurations there will be no leading zero on the HOUR resulting in an embedded space. As I post earlier, this method is dependant on the OS and your regional settings. Other techniques can be used but this should give you a good IDEA of what's involved. Hope this helps. PS. Please don't post new questions on someone elses post (called hijacking). Start your own. |
|