Xcopy not changing modified date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mlawton1986
Posts: 4
Joined: 21 Mar 2016 10:50

Xcopy not changing modified date

#1 Post by mlawton1986 » 21 Mar 2016 10:57

Hi,
In a batch script 'm doing a:
XCOPY <file> <destination>

and I expected the modified date of the file in the destination folder to be the time the command is executed but it is keeping the original modified timestamp...

I've tried doing a:
copy /b <file> +,,
before the XCOPY to attempt to change the timestamp before I copy but still keeps the original timestamp.

If I open up a cmd prompt and issue a "copy /b <file> +,," it correctly changes the modified timestamp to now... really confused as to why its not working in a batch script.

Any ideas? Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Xcopy not changing modified date

#2 Post by foxidrive » 21 Mar 2016 11:24

The file is not modified by xcopy, but it is using the copy syntax you showed.

What is the purpose of updating the timestamp? There are other ways of identifying a new file.

mlawton1986 wrote:I've tried doing a:
copy /b <file> +,,
before the XCOPY to attempt to change the timestamp before I copy but still keeps the original timestamp.

My guess is that the file isn't being copied because of the switches you are using with xcopy. But see below.

mlawton1986 wrote:If I open up a cmd prompt and issue a "copy /b <file> +,," it correctly changes the modified timestamp to now... really confused as to why its not working in a batch script.

Are you saying the copy syntax doesn't work? Put a pause after the command to view the error message - you're probably in the wrong working directory and the file is not where you expect it to be.

mlawton1986
Posts: 4
Joined: 21 Mar 2016 10:50

Re: Xcopy not changing modified date

#3 Post by mlawton1986 » 21 Mar 2016 12:51

The file copies fine so nothing wrong with the syntax.
The problem is that it keeps the original modified timestamp in the destination folder. I need that to be updated when it copes.

E.g. If I manually copy and paste the file to the directory it updates the modified date to now... I'd of thought x copy would do the same.

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: Xcopy not changing modified date

#4 Post by kwsiebert » 21 Mar 2016 15:48

mlawton1986 wrote:E.g. If I manually copy and paste the file to the directory it updates the modified date to now... I'd of thought x copy would do the same.

Check this again, because it does not do this on my Windows 7 system. All normal file copy operations leave the modified date unchanged, which is expected because the file was not modified.

copy /b <file> +,, should do what you want, but without seeing the rest of your code we can't determine if there is actually an error.

mlawton1986
Posts: 4
Joined: 21 Mar 2016 10:50

Re: Xcopy not changing modified date

#5 Post by mlawton1986 » 22 Mar 2016 09:34

Hello,

OK, here is the relevant bits of my code:

Code: Select all

SET SRC_LOC=C:\ML\From\
SET DATE=%date:~0,4%%date:~4,2%%date:~6,2%

for %%X IN (%SRC_LOC%Tester_%DATE%_*) do (
copy /b %%X +,,
)


But the modified date does not change.

mlawton1986
Posts: 4
Joined: 21 Mar 2016 10:50

Re: Xcopy not changing modified date

#6 Post by mlawton1986 » 22 Mar 2016 10:27

I worked it out... turns out I have to be in the directory...

Therefore I simply added:

Code: Select all

cd %SRC_LOC%


before the copy...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Xcopy not changing modified date

#7 Post by foxidrive » 22 Mar 2016 17:16

mlawton1986 wrote:I worked it out... turns out I have to be in the directory...


I told you that in my post. :D

Post Reply