Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a DOS command that isn't working for me

Status
Not open for further replies.

TomSalvato

Technical User
Mar 24, 2010
64
US
Hello experts - I'm hoping this is a simple request, I haven't had to use too much DOS in recent years so I'm probably forgetting something common.

I need to do a basic file copy from one location to another, but I need to target file to get a date extension so that it doesn't overwrite files in the target folder.

copy CurrentPath\test.txt NewPath\test.txt

I need the file to be test_01302022.txt (though the format of the date isn't that important).

I know there's a data function, but I can't seem to get the system to accept the syntax.

This is what I was told to try ...

copy CurrentPath\test.txt NewPath\test-%DATE%.txt
This just gives me a syntax error.

Can anyone help me out with what I'm doing wrong?

Thanx as always,
-TS
 
Here is some code from the start of a batch file that I use.

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "fullstamp=%YYYY%-%MM%-%DD%-%HH%-%Min%-%Sec%"

set "backuplogname=backup-%YYYY%-%MM%-%DD%-%HH%-%Min%-%Sec%.txt"

Hope it helps.
 
Or, instead of DOS, you can use simple FileCopy in VBA (let's say, Excel) :)

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Thanks for the replies, guys. Forgive me, but I really am a novice with DOS commands at this point.

So the line I got from another site ...

copy TEST.txt TEST-%DATE%.txt is not even close? Keeping in mind, i just need a datestamp on the target file name, the format doesn't really matter.

-TS
 
I think the problem you have is that the date is in the format "31/01/2022" and dos does not like the "/" characters in the filename.

You will need to do something based on my earlier answer.
 
You're right, that is precisely how the 'date' function returns the date. I'll need to replace the \ with - symbols. I will fool around a bit using your previous posts. Thanks again. -TS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top