Link to home
Start Free TrialLog in
Avatar of compdigit44
compdigit44

asked on

Windows Batch File to Copied File and Check Date

I have a Windows XP computer and I'm writing a batch file to copy a file from my computer to a network location but I need to add a line for the batch file to let me know if the file being copied are older than the current ones in the folder... How would I do this?
Avatar of MSE-dwells
MSE-dwells
Flag of Yemen image

Xcopy /? <snipped>

/D:m-d-y     Copies files changed on or after the specified date.
             If no date is given, copies only those files whose
             source time is newer than the destination time.

... or perhaps you were being entirely literal when you said 'let me know if the file being copied are older'.  Do you simply want to be informed or block the copy of those files?
Avatar of compdigit44
compdigit44

ASKER

My requirements have now changed a bit: I now need xcopy to copy files from a folder to a network location "BUT" I need xcopy to select the proper folder of the week that has the most current data for example: xcopy would pull data from Mondays folder on Monday etc... How can I setup this script to have a variable to select the source folder by most recently modified?
I've been told by a number of individuals that changing requirements mid-way is taboo ... figured I'd mention it since I didn't know that was frowned upon myself.

Anyway, that said - there's not enough information -- you called it 'Monday's folder', but I can't copy from a source whose precise name I don't know, can you supply a more concise example please.
what about selecting the source folder by the date i.e: most reciently modified...
You're not getting it, I'm not struggling with the code, I just don't have sufficient info.  ... you need to supply me an example folder name -- source and target if different ...
Sorry about that...Here is my source folder structure
01-Mon
02-Tues
03-Wed
04-Thu
05-Fri
06-Sat
07-Sun
Each folder contains backup information for example Monday's folder has monday's backup etc..

The soure is o:\
Does this help
Closer -- what does the '01' in '01-Mon' represent, a day-index or a date, i.e. is this the entire range of possible folder names?
This is just used to represent the day of the week. I.E 01 for MOnday because it is the first day of the work week.
ASKER CERTIFIED SOLUTION
Avatar of MSE-dwells
MSE-dwells
Flag of Yemen image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what does the :~0,3% do ??

Could robocopy be used maybe?
It takes the first 3 characters of the current day/date string thereby returning an abbreviation of the day.

Re: robocopy - of course, use whatever you want, just replace the command syntax at the bottom,e.g -

if not "%FOLDER%"=="" robocopy <source>\%FOLDER% \\<server>\<share>\%FOLDER% /mir

... or whatever other switches suit your needs.