Computing.Net > Forums > Programming > what am i doing wrong?

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

what am i doing wrong?

Reply to Message Icon

Original Message
Name: ThePuFF
Date: April 25, 2007 at 02:33:52 Pacific
Subject: what am i doing wrong?
OS: nt4
CPU/Ram: p3 866
Comment:

im trying to rename some files but keep getting "system cannot find the file specified" while it does come up with the correct names in the driectory???
cd..
cd SFTPcomm
set count=0
for %%i in (clieop03.*) do (set name=%%i call :countadd)
:countadd
set /a count=count+1
ren "d:\sftpcomm\%name%" "d:\sftpcomm\r0003084.SFT.CLIEOP.A00%count%.TXT"
goto :eof

this is the output i get when dont set echo off
D:\SFTPcomm>rename.bat

D:\SFTPcomm>cd..

D:\>cd SFTPcomm

D:\SFTPcomm>set count=0

D:\SFTPcomm>for %i in (clieop03.*) do (set name=%i call :countadd )

D:\SFTPcomm>(set name=clieop03.b01 call :countadd )

D:\SFTPcomm>(set name=clieop03.b02 call :countadd )

D:\SFTPcomm>(set name=clieop03.i01 call :countadd )

D:\SFTPcomm>(set name=clieop03.i02 call :countadd )

D:\SFTPcomm>set /a count=count+1

D:\SFTPcomm>ren "d:\sftpcomm\clieop03.i02 call :countadd" "d:\sftpcomm\r0003084.
SFT.CLIEOP.A001.TXT"
The system cannot find the file specified.


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: April 25, 2007 at 03:29:48 Pacific
Reply: (edit)

You have to break the line with a CR/LF after Set name=%%i or to type a & if you want the TWO commands on the same line.

More, if you don't want to get the next error message code

set /a count=%count%+1 or

set /a count+=1

and code a GoTo :EOF before the label

:countadd

otherwise you reenter the subroutine after the loop ended.


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: April 25, 2007 at 05:44:10 Pacific
Reply: (edit)

Also, naming you batch with an internal command or reserved word [cd con type rename lpt] is generally a bad idea.



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: IVO
Date: April 25, 2007 at 06:50:52 Pacific
Reply: (edit)

Hi M2,

the batch is not named cd, otherwise it never started (the internal cd command would get priority over it); the cd.. (first command line in the script) sets the current directory to the parent of the one actually in execution.

BTW if you choose to code & avoid spaces in front of it (i.e. set name=%%i& call...)


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software