Every day after midnight I have to copy log file from day before.
Log names are in format exYYMMDD.log. So today (22.10.2011) I would have to copy file named ex111021.log into some directory.
Is it possible to do it in batch script? If not I could use powershell but would prefer not as it is not installed on my server.
Edit: With help of Siva Charan I created this (polish win7 - echo %date% prints YYYY-MM-DD)
set /a yest_Day = %date:~8,2%-%var:~-2,1%
copy ex%date:~2,2%%date:~5,2%%yest_Day%.log targetDir
In powershell :
$YesterdayfileName = [string]::format("{0:yyMMdd}", ((Get-Date).adddays(-1)))+".log
# today 22/20/2011 gives 111021.log
Copy-Item $YesterdayfileName c:\temp
Implement this way in Batch file.
copy sourcefilepath destinationfilepath
For today's date:
copy ex%date:~12,10%%date:~4,2%%date:~7,2%.log D:\
For yesterday's date:
set /a yest_Day = %date:~7,2%-%var:~-2,1%
copy ex%date:~12,10%%date:~4,2%%yest_Day%.log D:\
You have to provide proper file path before the file name ex111022.log / ex111021.log and destination too.
You can make a schedule for this batch file, which will run on daily basis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With