batch file command

I am using this type of batch file command

SET date=%date:~10,4%-%date:~4,2%-%date:~7,2%
set SAVESTAMP=%TIME::=-%

echo f | xcopy /f /y "C:\path\filename.txt" "D:\archive\filename%date%_%SAVESTAMP%.txt"

And it is creating the same file in my archive from 2-3 times. I've checked the original directory and there is only the one filename.txt file.

They all have the same date modified and size:

But the SAVESTAMP varies:
2017-12-13_14-35-19.03
2017-12-13_14-50-19.03
2017-12-13_14-55-48.94


thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I'm not working with  a text file. I'm working with a server file and although it supposedly only updates every 30 minutes, i'm wondering if its dynamic nature is causing this issue. Well, at least it's nothing within my control. Thanks for confirming.
0
 
NVITCommented:
> But the SAVESTAMP varies:
Of course. It's the same source file filename.txt. The difference is the destination filename (but the same file contents). It differs each time  because the date and time is set each time the batch runs. XCOPY is just copying the same filename.txt to different filenames.

What are you trying to do?
0
 
Bill PrewCommented:
This would indicate the batch file ran three times on that date at the times below.  Each time it copied the same file with the current time in the destination file name.  Is that not what you expected?  What causes the BAT file to execute?

14:35:19.03
14:50:19.03
14:55:48.94


»bp
1
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I click it once. It runs once. I get 3 copies of the same file with 3 timestamps seconds apart.

I only have the line in the file once. Not 3 times. I haven't run it 3 times.
0
 
NVITCommented:
> I click it once. It runs once. I get 3 copies of the same file with 3 timestamps seconds apart.

And this is the entire code?

SET date=%date:~10,4%-%date:~4,2%-%date:~7,2%
set SAVESTAMP=%TIME::=-%

echo f | xcopy /f /y "C:\path\filename.txt" "D:\archive\filename%date%_%SAVESTAMP%.txt" 

Open in new window


Maybe a sticking mouse button?

What happens if you open a CMD window and run the bat from there?

By the way, what is echo f | for?
0
 
Bill PrewCommented:
What is the name of the BAT file?


»bp
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I also run it from the scheduler. So sticking mouse isn't the issue.

It simulates the response asked if it is a file or directory if you don't use wildcards.

The reason you don't use copy is because only xcopy will create the directory, copy requires it already exist.

It sounds like you're all as stumped as I am. I thought maybe I was missing something. But it appears the issue is not my command.
0
 
NVITCommented:
It works fine here.
I run it once and end up with 1 file.
I run it again and end up with 2 files, the second with a different time stamp, as expected.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
No solution found. Perhaps due to dynamic nature of original file.
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.

All Courses

From novice to tech pro — start learning today.