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.
Xcopy not changing modified date
Moderator: DosItHelp
Re: Xcopy not changing modified date
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.
My guess is that the file isn't being copied because of the switches you are using with xcopy. But see below.
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.
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.
-
- Posts: 4
- Joined: 21 Mar 2016 10:50
Re: Xcopy not changing modified date
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.
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.
Re: Xcopy not changing modified date
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.
-
- Posts: 4
- Joined: 21 Mar 2016 10:50
Re: Xcopy not changing modified date
Hello,
OK, here is the relevant bits of my code:
But the modified date does not change.
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.
-
- Posts: 4
- Joined: 21 Mar 2016 10:50
Re: Xcopy not changing modified date
I worked it out... turns out I have to be in the directory...
Therefore I simply added:
before the copy...
Therefore I simply added:
Code: Select all
cd %SRC_LOC%
before the copy...
Re: Xcopy not changing modified date
mlawton1986 wrote:I worked it out... turns out I have to be in the directory...
I told you that in my post.