centurian102
asked on
Renaming a file in a batch file
I am writing a batch file to change the name of a file to the date, then move it to the server. I can't get it to work.
This is the batch file
SET FDATE=%DATE:~4,2%-%DATE:~7 ,2%-%DATE: ~10,4%
REN "C:\documents and settings\ccarlson\desktop\ tape.rpt" %FDATE%.rpt
Move "C:\documents and settings\ccarlson\desktop\ %FDATE%.tx t" "I:\All Ballys\SDSBckLogs\2007\Mar ch\"
pause
this is the errors
C:\Documents and Settings\ccarlson\Desktop> SET FDATE=7/-00-
C:\Documents and Settings\ccarlson\Desktop> REN "C:\documents and settings\ccarls
on\desktop\tape.txt" 7/-00-.txt
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop> Move "C:\documents and settings\ccarl
son\desktop\7/-00-.txt" "I:\All Ballys\SDSBckLogs\2007\Mar ch\"
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop> pause
Press any key to continue . . .
This is the batch file
SET FDATE=%DATE:~4,2%-%DATE:~7
REN "C:\documents and settings\ccarlson\desktop\
Move "C:\documents and settings\ccarlson\desktop\
pause
this is the errors
C:\Documents and Settings\ccarlson\Desktop>
C:\Documents and Settings\ccarlson\Desktop>
on\desktop\tape.txt" 7/-00-.txt
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
son\desktop\7/-00-.txt" "I:\All Ballys\SDSBckLogs\2007\Mar
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
Press any key to continue . . .
ASKER
I copied and pasted your script, but this is what I got.
C:\Documents and Settings\ccarlson\Desktop> SET FDATE=7/-00-
C:\Documents and Settings\ccarlson\Desktop> REN "C:\documents and settings\ccarls
on\desktop\tape.rpt" 7/-00-.rpt
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop> Move "C:\documents and settings\ccarl
son\desktop\7/-00-.rpt" "I:\All Ballys\SDSBckLogs\2007\Mar ch\"
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop> pause
Press any key to continue . . .
It works on another machine...I don't understand
C:\Documents and Settings\ccarlson\Desktop>
C:\Documents and Settings\ccarlson\Desktop>
on\desktop\tape.rpt" 7/-00-.rpt
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
son\desktop\7/-00-.rpt" "I:\All Ballys\SDSBckLogs\2007\Mar
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
Press any key to continue . . .
It works on another machine...I don't understand
the problem lies with your set fdate,
what is it you are trying to achieve?
what is it you are trying to achieve?
your using invalid characters in your file name, you cannot use /
SET FDATE=%DATE:~4,2%-%DATE:~7 ,2%-%DATE: ~10,4%
some systems will work this way - some won't.
The reason is,
echo %date%
on some systems produces
Tue 03/27/2007
others will produce
03/27/2007
Try echo %date% on this system and see what's returned..
some systems will work this way - some won't.
The reason is,
echo %date%
on some systems produces
Tue 03/27/2007
others will produce
03/27/2007
Try echo %date% on this system and see what's returned..
ASKER
I would like to take a file each day, named tape.rpt
and rename it with the day ie. 03/27/07
then move it to its respective folder on our server
thanks
and rename it with the day ie. 03/27/07
then move it to its respective folder on our server
thanks
ive got it, your trying to use fdate - a freeware program, you need to make sure thats installed on the pcs ur running the batch script on
Try this...
if %date:~0,1% GTR 9 goto :Daydate
SET FDATE=%DATE:~4,2%-%DATE:~7 ,2%-%DATE: ~10%
goto :setup
:Daydate
SET FDATE=%DATE:~0,2%-%DATE:~3 ,2%-%DATE: ~6%
:setup
REN "C:\documents and settings\ccarlson\desktop\ tape.rpt" %FDATE%.rpt
Move "C:\documents and settings\ccarlson\desktop\ %FDATE%.rp t" "I:\All Ballys\SDSBckLogs\2007\Mar ch\"
if %date:~0,1% GTR 9 goto :Daydate
SET FDATE=%DATE:~4,2%-%DATE:~7
goto :setup
:Daydate
SET FDATE=%DATE:~0,2%-%DATE:~3
:setup
REN "C:\documents and settings\ccarlson\desktop\
Move "C:\documents and settings\ccarlson\desktop\
ASKER
C:\Documents and Settings\ccarlson\Desktop>
03/27/2007
C:\Documents and Settings\ccarlson\Desktop>
Press any key to continue . . .
ASKER
C:\Documents and Settings\ccarlson\Desktop>
C:\Documents and Settings\ccarlson\Desktop>
C:\Documents and Settings\ccarlson\Desktop>
C:\Documents and Settings\ccarlson\Desktop>
on\desktop\tape.rpt" 7/-00-.rpt
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
son\desktop\7/-00-.rpt" "I:\All Ballys\SDSBckLogs\2007\Mar
The system cannot find the path specified.
C:\Documents and Settings\ccarlson\Desktop>
Press any key to continue . . .
Hmm - did I get that backwards?
try modifying this section:
if %date:~0,1% GTR 9 goto :Daydate
SET FDATE=%DATE:~0,2%-%DATE:~3 ,2%-%DATE: ~6%
goto :setup
:Daydate
SET FDATE=%DATE:~4,2%-%DATE:~7 ,2%-%DATE: ~10%
try modifying this section:
if %date:~0,1% GTR 9 goto :Daydate
SET FDATE=%DATE:~0,2%-%DATE:~3
goto :setup
:Daydate
SET FDATE=%DATE:~4,2%-%DATE:~7
ASKER
the above scipt, won't even let me pause it to see what it says
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your a genius...thanks
What did it end up being? The above was just for troubleshooting...
Glad it worked though - thanx for the grade! :^)
SET FDATE=%DATE:~4,2%-%DATE:~7
REN "C:\documents and settings\ccarlson\desktop\
Move "C:\documents and settings\ccarlson\desktop\
change it to:
SET FDATE=%DATE:~4,2%-%DATE:~7
REN "C:\documents and settings\ccarlson\desktop\
Move "C:\documents and settings\ccarlson\desktop\
and it should work...