Reputation: 97
OK, so I've done a bit of research but have hit a bit of a hurdle here. What I'm trying to do is, (using event scheduler), run a batch daily, that takes the "ips*.csv file (* is just the date format) for the previous day only and copy it elsewhere, for my test I used "destiny ips" folder. I think I've messed up on the last hurdle.
FORFILES /P "C:\Users\J\Desktop\ips bat\source ips" /M "ips*.csv" /C "cmd /c XCOPY C:\Users \J\Desktop\ips bat\source ips folder C:\Users\J\Desktop\ips bat\destiny ips" /D -1
Thanks for any help in advance.
Jonny
Upvotes: 0
Views: 1937
Reputation: 80013
for /f "delims=" %%i in (
'dir /b /o:-d "c:\users...etc...ips*.csv" ' ) do (
xcopy /d "%%i" "C:\Users\J\Desktop\ips bat\destiny ips\" &goto :eof
)
should do this very simply (in fact, it can all be on the one line) It will copy only the very latest version of the file to the destination - and then only if the destination file does not already exist (or is different from the version in source.) This should take care of any non-operational days like weekends or public holidays.
If the destination keeps ALL of the history (ie. there may be ips*.csv
files in the destination that are not in the source, but not vice-versa (other than the new one for "yesterday") ) then simply
xcopy /d "c:\users...etc...ips*.csv" "C:\Users\J\Desktop\ips bat\destiny ips\"
will suffice.
The critical points are:
(It stands to reason that ...etc... is the remainder of the pathname required - DOS is not psychic)
Upvotes: 1
Reputation: 273
To include special characters in the command line, use the hex code for the character in 0xHH format (ex. 0x09 is theTAB character, 0x22 is the double quote " character.) so "C:\Program Files\" becomes ^0x22C:\Program^ Files\^0x22
FORFILES
/P "C:\Users\J\Desktop\ips bat\source ips"
/M "ips*.csv"
/C "cmd /c
XCOPY ^0x22C:\Users\J\Desktop\ips^ bat\source ips folder^0x22
^0x22C:\Users\J\Desktop\ips^ bat\destiny ips^0x22"
/D -1
I have separated it onto multi-lines for readability, but you will want to put that back into one line.
Upvotes: 1
Reputation: 17258
This looks suspect-:
XCOPY C:\Users \J\Desktop\ips bat\source
Is it correct?
Upvotes: 0