Solved

Renaming a file in a batch file

Posted on 2007-03-27
16
226 Views
Last Modified: 2012-06-21
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%.txt" "I:\All Ballys\SDSBckLogs\2007\March\"


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\March\"
The system cannot find the path specified.

C:\Documents and Settings\ccarlson\Desktop>pause
Press any key to continue . . .
0
Comment
Question by:centurian102
  • 7
  • 6
  • 3
16 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801025
You're renaming it to .rpt, but trying to move it as txt...?

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%.txt" "I:\All Ballys\SDSBckLogs\2007\March\"

change it to:


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%.rpt" "I:\All Ballys\SDSBckLogs\2007\March\"
and it should work...
0
 

Author Comment

by:centurian102
ID: 18801069
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\March\"
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
0
 
LVL 4

Expert Comment

by:superblades
ID: 18801083
the problem lies with your set fdate,

what is it you are trying to achieve?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 4

Expert Comment

by:superblades
ID: 18801093
your using invalid characters in your file name, you cannot use /
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801099
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..
0
 

Author Comment

by:centurian102
ID: 18801100
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
0
 
LVL 4

Expert Comment

by:superblades
ID: 18801105
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801123
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%.rpt" "I:\All Ballys\SDSBckLogs\2007\March\"
0
 

Author Comment

by:centurian102
ID: 18801125

C:\Documents and Settings\ccarlson\Desktop>echo 03/27/2007
03/27/2007

C:\Documents and Settings\ccarlson\Desktop>pause
Press any key to continue . . .
0
 

Author Comment

by:centurian102
ID: 18801130

C:\Documents and Settings\ccarlson\Desktop>if 0 GTR 9 goto :Daydate

C:\Documents and Settings\ccarlson\Desktop>SET FDATE=7/-00-

C:\Documents and Settings\ccarlson\Desktop>goto :setup

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\March\"
The system cannot find the path specified.

C:\Documents and Settings\ccarlson\Desktop>pause
Press any key to continue . . .
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801159
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%
0
 

Author Comment

by:centurian102
ID: 18801193
the above scipt, won't even let me pause it to see what it says
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18801219
echo %date%
if %date:~0,1% GTR 9 echo %date% appears to have the 'day' && goto :Daydate
echo %date% doesn't have the dayname...
SET FDATE=%DATE:~0,2%-%DATE:~3,2%-%DATE:~6%
goto :setup
:Daydate
SET FDATE=%DATE:~4,2%-%DATE:~7,2%-%DATE:~10%
:setup
echo Renaming file with this command...
echo REN "C:\documents and settings\ccarlson\desktop\tape.rpt" %FDATE%.rpt
pause
REN "C:\documents and settings\ccarlson\desktop\tape.rpt" %FDATE%.rpt
echo moving file with this command...
echo Move "C:\documents and settings\ccarlson\desktop\%FDATE%.rpt" "I:\All Ballys\SDSBckLogs\2007\March\"
pause
Move "C:\documents and settings\ccarlson\desktop\%FDATE%.rpt" "I:\All Ballys\SDSBckLogs\2007\March\"
0
 

Author Comment

by:centurian102
ID: 18801236
Your a genius...thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801266
What did it end up being?  The above was just for troubleshooting...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18801272
Glad it worked though - thanx for the grade! :^)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing trusted root certificate 12 44
Graphics card for a new Dell 5810 workstation 16 102
extended monitor print screen 8 28
Two "Pin to Start…" options in Windows 10 4 26
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

813 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

10 Experts available now in Live!

Get 1:1 Help Now