galantico Posted May 8, 2007 Posted May 8, 2007 I currently have a batch file that does backup of some folders and piping the output to a file called BackupLog.txt. This file gets overwritten each time the backup task runs. I would like to append the date to this filename such that there will be a new output file each day. eg. BackupLog08052007.txtAnyone can help me with the syntax? I currently have >> "D:\BackupLog.txt"Thanks!!
gunsmokingman Posted May 8, 2007 Posted May 8, 2007 I currently have a batch file that does backup of some folders and piping the output to a file called BackupLog.txt. This file gets overwritten each time the backup task runs. I would like to append the date to this filename such that there will be a new output file each day. eg. BackupLog08052007.txtAnyone can help me with the syntax? I currently have >> "D:\BackupLog.txt"Thanks!!Here try this then add what you need to yours.@Echo OffCLSColor B1Mode 65,7Title Date DemoSET Y1=%date:~10,4%SET M1=%date:~4,2%SET D1=%date:~7,2%SET C1=%M1%%D1%%Y1%Echo.Echo ^> Year %Y1%Echo ^> Month %M1%Echo ^> Day %D1%Echo ^> Today %Date%Set /P = ^<^> Press To Close Cmd Window %C1%
galantico Posted May 9, 2007 Author Posted May 9, 2007 @ECHO OFFREM Backup "DB Folder"XCOPY "C:\Program Files\McAfee\ePO\3.6.0\DB\*.*" "D:\TNSP Cardiff\Disaster Recovery\ePO DB\" /E /H /Y >> "D:\TNSP Cardiff\Disaster Recovery\ePO DB\BackupLogs.txt"EXIT--------------------the above is what i have at the moment, how do i edit it to get my desired results?thanks.
jcarle Posted May 9, 2007 Posted May 9, 2007 gunsmokingman... I'm in awe. You speak Batch like English is your second language...
gunsmokingman Posted May 9, 2007 Posted May 9, 2007 gunsmokingman... I'm in awe. You speak Batch like English is your second language...Actually English is the only language I speak. Yzowl knowledge of batch surpasses my abilities in that language.
Yzöwl Posted May 9, 2007 Posted May 9, 2007 That is correct Incidentally because people have different locales, the format of the date differs therefore creating different results. Here's mine:My suggestion, being how I speak the language far more fluently would be this!@ECHO OFF&SETLOCALFOR /F "TOKENS=1-3 DELIMS=-/." %%a IN ( 'ECHO/EXIT^|%COMSPEC%/Q/K PROMPT $D') DO SET "D_=%%a%%b%%c"ECHO/ Your date appendage is: %D_%
gunsmokingman Posted May 9, 2007 Posted May 9, 2007 That is correct Incidentally because people have different locales, the format of the date differs therefore creating different results. Here's mine:My suggestion, being how I speak the language far more fluently would be this!@ECHO OFF&SETLOCALFOR /F "TOKENS=1-3 DELIMS=-/." %%a IN ( 'ECHO/EXIT^|%COMSPEC%/Q/K PROMPT $D') DO SET "D_=%%a%%b%%c"ECHO/ Your date appendage is: %D_%Nice Batch, YzowlMy question is how would you remove the shortday name that appears at the beggining of %D_%, I only ask because the poster wanted a format like this BackupLog08052007.txt.This is what I got when I ran the script Your date appendage is: Wed 05092007, could youuse something like this to remove the shortname of the day on all locals.@ECHO OFF&SETLOCALFOR /F "TOKENS=1-3 DELIMS=-/." %%a IN ( 'ECHO/EXIT^|%COMSPEC%/Q/K PROMPT $D') DO SET "D_=%%a%%b%%c"SET R1=%D_:~4,8%ECHO/ Your date appendage is: %R1%pauseThis produced on my machineYour date appendage is: 05092007Would this work with all locals.This is how I would do it using VBS ScriptDim Today, StrD, StrM, StrTD, StrYToday = DateStrD = Day(Today)StrM = Month(Today)StrY = Year(Today) If Len(StrD) < 2 Then StrD = "0" & StrD End If If Len(StrM) < 2 Then StrM = "0" & StrM End If WScript.Echo StrY & StrM & StrD
Yzöwl Posted May 9, 2007 Posted May 9, 2007 I wasn't aware that the day was included with the date in that particular instance. At first I thought it a possible Vista quirk, however the cmd works correctly for me in Vista too.Try it this way instead@ECHO OFF&SETLOCALFOR /F "TOKENS=1-3 DELIMS=-/." %%a IN ('DATE/t') DO SET "D_=%%a%%b%%c"ECHO/ Your date appendage is: %D_%Also in order to achieve the result you tried above there is no need to extract the eight characters which occur after the first four. the problem with this method is that for those of us withour 'Wed ' we would only get back the last four characters, (2007 in my case). What you should have done was just add:SET "D_=%D_:~-8%"That will only use the last eight characters in all cases.
IcemanND Posted May 9, 2007 Posted May 9, 2007 I get different responses from 'date /t' depending upon the machine I run it on. Some returnthe DayofWeek some don't, all of them XP.
Yzöwl Posted May 9, 2007 Posted May 9, 2007 You people are hard to please...@ECHO OFF&SETLOCALFOR /F "DELIMS=0123456789 " %%? IN ("%DATE%") DO SET "D_=%%?"FOR /F "TOKENS=1-3 DELIMS=%D_% " %%a IN ("%DATE%") DO SET "D_=%%a%%b%%c"ECHO/ Your date appendage is: %D_%How does that do?
galantico Posted May 10, 2007 Author Posted May 10, 2007 well, the diff date formats is due to the regional settings on your machines.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now