copy \\server01\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server02\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server03\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server04\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
This is my current script and I have to change the date weekly. I am looking for a script that will look at today's current date minus one day and can modify the 12 04 28. (Year Month Day sample 120408). I need yesterday's date. This script is in DOS
Save yourself a world of pain, use a better language!
Here is the script you want in PowerShell:
Use these instructions to help you schedule the copy
If you can use powershell, why not do it with this simple one line:
It is an example that outputs actual Year, Month, Day, Hour, Minute and Second.
See last part, it is the format you want, so you can get it with the format you want.
Explanation of what it does:
.ToString(
...)
it formats the output of[DateTime]::Now
in the formatyyyyMMdd_hhmmss
And if you want it in a bacth file you can use the trick of
for /f "delims="
, see an example:If you want to use it inside a .BAT or .CMD file you must double the % as this:
Importat note: The ^ character is t avoid for see the ) as final, same as \ does this " inside powershell, etc. It is a meta-charater that tells next character must not be interpreted.
And if you need datetime inside a variable on a batch, see this:
P.D.: There are side effects on using powershell, it changes CMD window size and font (and let them changed after exit), also sometimes it takes some seconds to run such simple command.
As retrieving yesterdays date involves various boundaries (month, years, leap years) it quickly becomes slightly more complex than one thinks. The below script is a slight modification of this post and depends on your machines language settings (run
DATE /T
on your command line).Doing this sort of thing in cmd batch files is purely masochistic.
But in any other language it is easy (bash under cygwin, probably powershell; even vbscript might make this reasonably easy).
So just use any other scripting language to either do it all, or to write out a temporary batch file and execute it.
An example in perl:
Say it's called writebatch.pl. Then your script could be something like
Or you could do the copies directly from the script. In Perl, you would use the File::Copy module. If you chose any other scripting tool, it will also have some file copy function.
If your main script has to be in Windows Shell Script, my solution for this would be to get the .CMD file to create a [small] .VBS file in %TEMP%, then launch it using a call to cscript.exe, wrapped in a for /f command. The actual VBScript can then use DateDiff. I've used this technique on our Windows Server 2003 boxes, where we haven't deployed PowerShell by default. If you're on a Windows NT6 platform, use PowerShell.
Date Time
Only Date
for /f "delims=" %%a in ('powershell -Command [DateTime]::Today.AddDays^(-1^).ToString^(\"yyyyMMdd\"^)') do ( set onedayold=%%a )