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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
> 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 PrewIT / Software Engineering ConsultantCommented:
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
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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

NVITEnd-user supportCommented:
> 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 PrewIT / Software Engineering ConsultantCommented:
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
NVITEnd-user supportCommented:
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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
No solution found. Perhaps due to dynamic nature of original file.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.