Solved

DOS Rename error

Posted on 2006-11-20
15
331 Views
Last Modified: 2012-06-27
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!
0
Comment
Question by:MetDia
  • 5
  • 5
  • 4
15 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 17980062
Why not change it to:

ren SL1.dat sl1%date:~0,2%%date:~3,2%%date:~-4,4%.bak
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980075
if that fails for you - please post the results by modifying the above to:

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
0
 

Author Comment

by:MetDia
ID: 17980134
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...
0
 
LVL 3

Expert Comment

by:JRockSolid
ID: 17980291
Try this :

ren SL1.dat SL1%date:~4,2%-%date:~7,2%-%date:~10,12%.bak
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980321
Try this from a command prompt:

echo %date%
and post the results...
0
 
LVL 3

Assisted Solution

by:JRockSolid
JRockSolid earned 250 total points
ID: 17980340
Sorry i messed up  :

SL1%date:~4,2%-%date:~7,2%-%date:~10,12%.bak  gives you
SL111-20-2006.bak

SL1%date:~10,12%-%date:~4,2%-%date:~7,2%.bak  gives you
SL12006-11-20.bak
0
 

Author Comment

by:MetDia
ID: 17980384
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!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 67

Expert Comment

by:sirbounty
ID: 17980410
I would've thought I'd have at least gotten an assist here...
0
 

Author Comment

by:MetDia
ID: 17980436
so sorry sirbounty... I have no clue how to give an assist...
is there a way I can change that?
0
 
LVL 3

Expert Comment

by:JRockSolid
ID: 17980515
Yes an assist was defanately in order
Pleasse ask the moderators to help you change it
0
 
LVL 3

Expert Comment

by:JRockSolid
ID: 17980527
Community Support / Customer Service is here:
http://www.experts-exchange.com/Community_Support/
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980587
Cool - thanx.
0
 

Author Comment

by:MetDia
ID: 17981076
Thanks guys!!
Won't do that error again!

0
 
LVL 3

Expert Comment

by:JRockSolid
ID: 17981211
Thank you MetDia
and you as well sir
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AS400 Logging Print device 2 74
Daisy Chaining Scheduled Tasks in Task Scheduler 4 119
Windows 10 PRo Upgrade 21 72
Hibernate on windows 10 18 123
Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now