In my batch file, I wonder why I can't create a hook for error handling if rename
fails. I create a folder foo
and have a shell changing its cwd to foo so that the folder should not be renamable. Then I start my script:
for %%x in (%PROGRAMFILES(X86)%") do (
for %%y in (foo) do (
if exist "%%~x\%%~y" (
rename "%%~x\%%~y" _to_be_removed
echo %ERRORLEVEL%
IF NOT %ERRORLEVEL% EQU 0 (echo We got a problem.)
)
)
)
Unfortunately, I get the notification that the folder cannot be deleted because it is in use:
Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.
0
Huh? rename
failed, but %ERRORLEVEL%
is zero? This should not be possible, no?