Batch Files Check Date

Started by
7 comments, last by Adam_42 16 years, 1 month ago
Hi all, Can anyone help me.. I need to write up a batch file that will check the date modified of the file in G drive and if it is the same at the one at U drive then it will do nothing. But if it is different than it will copy the G drive file to U drive. Help Needed.. Thanks a million..
Advertisement
Assuming windows (does "batch file" apply to other OS?), you can use:

xcopy source destination /D

This should copy the source to the destination, only if source is more recent than destination. Type:

help xcopy

at the dos prompt to see a list of options and their explanations.
xcopy /d <source> <destination>
i tried both the codes u guys gave. but it keep giving me insufficient parameters.

xcopy /D G:\Documents\Daily Updates.xls U:\Upload\Daily Update
I think you need to specify the parameters after the source and dest names. Also, you want to use quotes around your paths if they have spaces. So try:

xcopy "G:\Documents\Daily Updates.xls" "U:\Upload\Daily Update" /D
Thank you so much.

it works now. my mistake for not adding the ""

i have another question. if my file in G drive is for example FILED and FILEM. but they actually contain the same information just that during month end they will provide me with FILEM. whereas daily they will provide me with FILED. is there a way for me to copy the files and name in under a generic name under U drive.
You can copy a whole directory to another directory... not sure how you would selectively sometimes copy FILED and other times FILEM, without just copying the whole directory (getting both files effectively)... at least not without getting fancier in your batch file, or switching to python or C# to do the job.
hmmm i'll see what i can do..

thanks =D
I think this would do the trick - destination will contain the newer of fileD.xls and fileM.xls, renamed to file.xls:

xcopy "G:\Documents\fileD.xls" "U:\Upload\Daily Update\file.xls" /Dxcopy "G:\Documents\fileM.xls" "U:\Upload\Daily Update\file.xls" /D

This topic is closed to new replies.

Advertisement