# Batch Files Check Date

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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..

##### Share on other sites
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.

##### Share on other sites
xcopy /d <source> <destination>

##### Share on other sites
i tried both the codes u guys gave. but it keep giving me insufficient parameters.

##### Share on other sites
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:

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
hmmm i'll see what i can do..

thanks =D

##### Share on other sites
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