MetDia
asked on
DOS Rename error
Hi,
I have a batch file that executes some SQL statements on a text file and then renames the file with the date...
from SL1.dat to SL12006-11-19.bak
my problem is that it doesn't rename the file with the Date... only renames it to SL1.bak
here's the dos code:
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
REN SL1.dat SL1%TODAY%.bak
is there an error in the code? does it matter if I'm on XP and it was originally written on 2000?
what should I correct?
Thanks! I'm on a deadline... thanks!
I have a batch file that executes some SQL statements on a text file and then renames the file with the date...
from SL1.dat to SL12006-11-19.bak
my problem is that it doesn't rename the file with the Date... only renames it to SL1.bak
here's the dos code:
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
REN SL1.dat SL1%TODAY%.bak
is there an error in the code? does it matter if I'm on XP and it was originally written on 2000?
what should I correct?
Thanks! I'm on a deadline... thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this statement works:
ren SL1.dat sl1%date:~0,2%%date:~3,2%% date:~-4,4 %.bak
but it is giving me this:
sl1206-1-20.bak
instead of this:
sl12006-11-20.bak
is there a small error in the statement?
the other statement:
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
echo %today%
pause
REN SL1.dat SL1%TODAY%.bak
does not work and doesn't rename the file properly...
the only error message is "ECHO deactivated"
I'd wrather use the first statement because it looks more simple but just need to fix the date...
ren SL1.dat sl1%date:~0,2%%date:~3,2%%
but it is giving me this:
sl1206-1-20.bak
instead of this:
sl12006-11-20.bak
is there a small error in the statement?
the other statement:
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
echo %today%
pause
REN SL1.dat SL1%TODAY%.bak
does not work and doesn't rename the file properly...
the only error message is "ECHO deactivated"
I'd wrather use the first statement because it looks more simple but just need to fix the date...
Try this :
ren SL1.dat SL1%date:~4,2%-%date:~7,2% -%date:~10 ,12%.bak
ren SL1.dat SL1%date:~4,2%-%date:~7,2%
Try this from a command prompt:
echo %date%
and post the results...
echo %date%
and post the results...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
doesn't rename it correctly either...
it gives me SL1-1--2-.bak now...
I tried playing with the different values until I stopped on:
ren SL1.dat SL1%date:~0,10%.bak
and it works perfectly!
Thank you very much JRockSold!
it gives me SL1-1--2-.bak now...
I tried playing with the different values until I stopped on:
ren SL1.dat SL1%date:~0,10%.bak
and it works perfectly!
Thank you very much JRockSold!
I would've thought I'd have at least gotten an assist here...
ASKER
so sorry sirbounty... I have no clue how to give an assist...
is there a way I can change that?
is there a way I can change that?
Yes an assist was defanately in order
Pleasse ask the moderators to help you change it
Pleasse ask the moderators to help you change it
Community Support / Customer Service is here:
https://www.experts-exchange.com/Community_Support/
https://www.experts-exchange.com/Community_Support/
Cool - thanx.
ASKER
Thanks guys!!
Won't do that error again!
Won't do that error again!
Thank you MetDia
and you as well sir
and you as well sir
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F%%G%%H)
echo %today%
pause
REN SL1.dat SL1%TODAY%.bak