|
Answer» I want to create a batch file which will create a dumpfile every DAY. So I want to set the name of the dump file as production_. Now how to include date in the file name please helpYou could assign values to variables like dd, mm, yy or yyyy as follows: set dd=%date:~7,2% set mm=%date:~4,2% set yy=%date:~12,2% or set yyyy=%date:~10,4%
where: :~ will get a substring that starts in the position specified the fist number getting as many character as specified in the second number (after the comma) note that the fist position starts at 0 %date% is the system date, usually like "Wed 01/19/2005"
Then you call your variables as usual (%var%) to rename FILES, like REN myFile.txt myFile%yy%%mm%%dd%.txt or REN myFile.txt myFile%yyyy%%mm%%dd%.txt
Of course, you could directly do everything in one STEP: REN myFile.txt myFile%date:~12,2%%date:~4,2%%date:~7,2%.txt or REN myFile.txt myFile%date:~10,4%%date:~4,2%%date:~7,2%.txt
Enjoy!
-Carolina Many many thanks Carolina This serves my purpose. Thanks jayati
Dang. I can't get this to work at all (the substringing). Is there some CMD extension that I have to turn on. I am on NT.Try this:
@echo off for /f "tokens=1-4 delims=/ " %%i in ("%DATE%") do ren filename production_ %%j%%k%%l
%%j = mm %%k = dd %%l = yy
You may have to re-arrange the variables if your date format is not mm/dd/yy
Hope this helps.
|