Name: sfitzger Date: September 7, 2007 at 07:46:52 Pacific Subject: Find / Replace text in a batch file OS: Windows 2000 CPU/Ram: dont know Model/Manufacturer: hp
Comment:
I have tried to accomplish this but without luck. I run a .bat file everyday to pull 10 .nmon files down from a server then anaylze them. The files contain the date -1 day previous which u can see in my script. What I am trying to do is replace the date in the script.txt file with the %mydate% variable so I don't have to manually change it everday when I run the bat. Please let me know if u can help thanks!
::== ::@echo off for /f "tokens=2" %%d in ('echo %date%') do ( for /f "tokens=1-3 delims=/" %%j in ('echo %%d') do ( set month=%%j set day=%%k set year=%%l ) ) set /a day=%day%-1 if %day% lss 10 ( set day=0%day% ) if %day%==00 ( set day=01 ) set year=%year:~2,3% set mydate=%month%%day%%year% cd C:\NmonReports mkdir %mydate% mkdir %mydate%-reports pause ftp -i -s:C:\script.txt pause copy C:\NmonReports\*.nmon C:\NmonReports\%mydate% "C:\Program Files\WinZip\WZZIP.EXE" -a -P -r C:\NmonReports\%mydate% "C:\NmonReports\%mydate%" move C:\NmonReports\%mydate%.zip C:\NmonReports\%mydate% pause "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\nmon analyser v317.xls" "C:\Program Files\WinZip\WZZIP.EXE" -a -P -r C:\NmonReports\%mydate%-reports "C:\NmonReports\%mydate%-reports" copy C:\NmonReports\%mydate%-reports.zip E:\ del C:\NmonReports\*.nmon pause
Your method of calculating the date of the previous day has a bug. If it's the 1st day of the month, you set day to 00 then the very next if statement sets it back to the 1st (formating it with a leading 0) instead of the last day of the previous month.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE