.bat files entries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a simple batch file that copies files from one drive to another. And
I know how to rename the file in the new location... but my problem is that I
want to date/time stamp the new file name. For example, I want file test.txt
to be renamed test(currentdatecurrenttime).txt. Is there an entry that
accommodates this?

Thanks!
 
ITGal said:
I've got a simple batch file that copies files from one drive to another. And
I know how to rename the file in the new location... but my problem is that I
want to date/time stamp the new file name. For example, I want file test.txt
to be renamed test(currentdatecurrenttime).txt. Is there an entry that
accommodates this?

Thanks!

Try this:
1 @echo off
2 for /F "tokens=2" %%a in ('echo %date%') do set date_=%%a
3 for /F "delims=." %%a in ('echo %time%') do set time_=%%a
4 set date_=%date_:/=-%
5 ren Test.txt "Test %date_% %time_%.txt

Remove the line numbers before running the batch file.
 
Thank you for the help. It still isn't working though. This is exactly what I
have in my .bat program. It is copying the file, but it is not renaming. Do
you see where I'm messing up?

@echo off
net use f: \\global_nt\Translog
xcopy c:\gblware\apollo.air h:\airfilesold /D
for /F "tokens=2" %%a in ('echo %date%') do set date_=%%a
for /F "delims=." %%a in ('echo %time%') do set time_=%%a
set date_=%date_:/=-%
ren h:\airfilesold\apollo.air log %date_% %time_%.air
netuse /delete f:
cls
 
Instead of placing "cls" at the end of your batch file,
thus hiding what's going on, place a pause so that
you can see what's going on!

1 @echo off
2 net use f: \\global_nt\Translog
3 xcopy c:\gblware\apollo.air h:\airfilesold /D
4 for /F "tokens=2" %%a in ('echo %date%') do set date_=%%a
5 for /F "delims=." %%a in ('echo %time%') do set time_=%%a
6 set date_=%date_:/=-%
7 echo ren h:\airfilesold\apollo.air log %date_% %time_%.air
8 ren h:\airfilesold\apollo.air log %date_% %time_%.air
9 pause
10 netuse /delete f:

- What exactly does line 7 show when it executes?
- What does line 8 report when it runs?
- There is no "netuse" command (line 10). It shoud be "net use".
- You may have to add a /y switch to line 3.
- What do you see in a Command Prompt when you type
these commands:
echo %date%
echo %time%
 
Surely you need quotes round the destination filename... i.e.
As you have spaces in the second file name, It'll give an error saying that
the command syntax is not correct.
As previous poster said, you'll not see this because you CLS immediately
after...

try adding quotes and see if it works...


@echo off
net use f: \\global_nt\Translog
xcopy c:\gblware\apollo.air h:\airfilesold /D
for /F "tokens=2" %%a in ('echo %date%') do set date_=%%a
for /F "delims=." %%a in ('echo %time%') do set time_=%%a
set date_=%date_:/=-%
ren h:\airfilesold\apollo.air "log %date_% %time_%.air"
netuse /delete f:
cls
 
My original proposal did actually have the required quote
but it would have been nicer if I had included the trailiing
quote. Thanks for pointing it out!
 
was thinking more of ITgal's second post... perhaps I should have replied
direct to that.
still working these newsgroup things out ;-)

I make a good wage out of not knowing what I'm talking about... so no
offence meant!
 
One of the great features of newsgroups is the peer review
that every reply gets. This weeds out incorrect or bad advice,
and it brings mistakes to the surface. I never take offence at
other posters pointing out the errors of my ways - to the
contrary: I'm glad someone checks what I have written so
that the OP gets the best possible advice.
 
Back
Top