• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

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?
0
compdigit44
Asked:
compdigit44
  • 6
  • 5
1 Solution
 
MSE-dwellsCommented:
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?
0
 
compdigit44Author Commented:
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?
0
 
MSE-dwellsCommented:
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
compdigit44Author Commented:
what about selecting the source folder by the date i.e: most reciently modified...
0
 
MSE-dwellsCommented:
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 ...
0
 
compdigit44Author Commented:
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
0
 
MSE-dwellsCommented:
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?
0
 
compdigit44Author Commented:
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.
0
 
MSE-dwellsCommented:
Something like this -

[BEGIN FILE]

@echo off

set FOLDER=

if /i "%DATE:~0,3%"=="Mon" set FOLDER=01-Mon
if /i "%DATE:~0,3%"=="Tue" set FOLDER=02-Tue
if /i "%DATE:~0,3%"=="Wed" set FOLDER=03-Wed
if /i "%DATE:~0,3%"=="Thu" set FOLDER=04-Thu
if /i "%DATE:~0,3%"=="Fri" set FOLDER=05-Fri
if /i "%DATE:~0,3%"=="Sat" set FOLDER=06-Sat
if /i "%DATE:~0,3%"=="Sun" set FOLDER=07-Sun

if not "%FOLDER%"=="" xcopy <source>\%FOLDER% \\<server>\<share>\%FOLDER% /s/e/h

[END FILE]
0
 
compdigit44Author Commented:
what does the :~0,3% do ??

Could robocopy be used maybe?
0
 
MSE-dwellsCommented:
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.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now