Ren does not always work

P

Paul

I have experienced intermittent problems when using ren in
a batch file running from the command prompt in W2K.
Sometimes it does not rename the directory or file. This
has happened more than once in batch files that were
running flawlessly under the command prompt in NT. I have
had to add a check to the batch scripts to make sure the
rename worked and to retry if not. The maddening thing is
the batch files could run daily for a month or two before
encountering this error. A contributing factor may be
that we are renaming files and directories on compressed
directories. Are there any known patches to correct this?
 
M

Marty List

Paul said:
I have experienced intermittent problems when using ren in
a batch file running from the command prompt in W2K.
Sometimes it does not rename the directory or file. This
has happened more than once in batch files that were
running flawlessly under the command prompt in NT. I have
had to add a check to the batch scripts to make sure the
rename worked and to retry if not. The maddening thing is
the batch files could run daily for a month or two before
encountering this error. A contributing factor may be
that we are renaming files and directories on compressed
directories. Are there any known patches to correct this?


The REN command should fail with an error message and an exit code.

Are you saving the output from your scripts anywhere?

Are you checking the value of %ERRORLEVEL% after the REN command? This
number should be a clue, for example if it is 32 that means some app had a
share lock on it:

C:\>Net HelpMsg 32

The process cannot access the file because it is being used by another
process.
 
M

Marty List

Paul said:
I have the rename in a loop that keeps trying until it
succeeds. It failed 8 times with an errorlevel of 1
before completing successfully.

The rename itself is the DO part of the FOR command. the
exact line is:
for %%i in (%FileDir%\%FileName%.OIM) do ren %%i %
AFTSUser%.BTO.%ProcessName%.%FileName%.OIM.%rdate1%

Errorlevel 1 says that this is an incorrect function. Any
thoughts?


I'm running XP & 2003 at the moment, I don't have access to 2000 right now.
This could be different on 2000, but on XP the REN command will fail with
errorlevel 1 when the file doesn't exist or when syntax is incorrect. Maybe
the file was not present yet, and it became available while you were
looping? Or maybe one of your variables had invalid characters, or was
empty because a file didn't exist yet or something, and then after it looped
several times the variable was correct?

C:\>Ver

Microsoft Windows XP [Version 5.1.2600]

C:\>Echo %ERRORLEVEL%
0

C:\>Ren & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>Ren sourceonly & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>Ren source :invaliddestination// & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>ren bogus1 bogus2
The system cannot find the file specified.

C:\>Echo %ERRORLEVEL%
1
 
M

Mark Zbikowski \(MSFT\)

It might be nice to post the precise text on output.

--
Disclaimer: This posting is provided "AS IS" with no warranties, and confers
no rights.


Marty List said:
Paul said:
I have the rename in a loop that keeps trying until it
succeeds. It failed 8 times with an errorlevel of 1
before completing successfully.

The rename itself is the DO part of the FOR command. the
exact line is:
for %%i in (%FileDir%\%FileName%.OIM) do ren %%i %
AFTSUser%.BTO.%ProcessName%.%FileName%.OIM.%rdate1%

Errorlevel 1 says that this is an incorrect function. Any
thoughts?


I'm running XP & 2003 at the moment, I don't have access to 2000 right now.
This could be different on 2000, but on XP the REN command will fail with
errorlevel 1 when the file doesn't exist or when syntax is incorrect. Maybe
the file was not present yet, and it became available while you were
looping? Or maybe one of your variables had invalid characters, or was
empty because a file didn't exist yet or something, and then after it looped
several times the variable was correct?

C:\>Ver

Microsoft Windows XP [Version 5.1.2600]

C:\>Echo %ERRORLEVEL%
0

C:\>Ren & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>Ren sourceonly & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>Ren source :invaliddestination// & Echo %ERRORLEVEL%
The syntax of the command is incorrect.
1

C:\>ren bogus1 bogus2
The system cannot find the file specified.

C:\>Echo %ERRORLEVEL%
1
 
N

Ndi

Errorlevel 1 says that this is an incorrect function. Any
thoughts?

You are mistaking error levels and error codes. Error *code* 1 is "Incorrect
function" and are defined by the OS. Errorlevel is defined by the
application and it is usually generic, most programs use 0 for success, 1
for error and sometimes other codes:

GetType Syntax

[...]

GetType queries the registry for the workstation's install type, and sets
the error level (%ErrorLevel%) as follows:
Error level :: Meaning
1: Windows NT Workstation
2: Windows 2000 Professional installation
3: Windows NT Server Non-Domain Controller
4: Windows 2000 Server Non-Domain Controller
5: Windows NT Server Domain Controller
6: Windows 2000 Server Domain Controller
7: Windows NT [Enterprise/Terminal] Server Domain Controller
8: Windows NT [Enterprise/Terminal] Server Non-Domain Controller

I remember chkdsk or scanidsk using 0 for "no errors', 1 for "errors found,
but fixed" and 2 for not fixed. And 1 was also for scan cancelled. Yes, I
think it was the auto-check scandisk in W9x for dirty volumes.

Errorlevel is application defined and I suspect that errorlevel of 1 is "not
done" in REN.
 
A

Al Dunbar [MS-MVP]

Please pardon the intrusion, all.

Marty: please drop me an e-mail (remove all spam-related stuff in e-mail
address, including punctuation). I'll explain why in reply.


/Al
 
M

Marty List

Al Dunbar said:
Please pardon the intrusion, all.

Marty: please drop me an e-mail (remove all spam-related stuff in e-mail
address, including punctuation). I'll explain why in reply.


/Al


I sent an email to your address with "-no--spam" removed, but I haven't
heard back so I may have guessed wrong at the address. My address is
'public"AT"optimumx"DOT"com'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top