Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rem http://stackoverflow.com/questions/2593133/batch-file-ren-commands-errorlevel-returns-0-even-on-failure/6969940#6969940
- rem Screenshot of the results when having an "Access Denied" error and "The system cannot find the file specified." error when using 'ren' command, both cases DO set the ERRORLEVEL to "1":
- rem http://i.imgur.com/BQb2Ydg.png
- @echo OFF
- SET directory=d:\downloads\testdir
- SET rename_what_filename=bla.txt
- SET rename_what_path=%directory%\%rename_what_filename%
- SET rename_to=sad.txt
- echo Renaming "%rename_what_filename%" to "%rename_to%" in the following directory: "%directory%"
- ren %rename_what_path% %rename_to%
- if not %errorlevel%==0 (
- echo There was a problem renaming the file.
- ) else (
- echo Renaming was successful.
- )
- echo Errorlevel: "%errorlevel%"
- echo.
- SET rename_what_filename=test.txt
- SET rename_what_path=%directory%\%rename_what_filename%
- SET rename_to=asdsad.txt
- echo Renaming "%rename_what_filename%" to "%rename_to%" in the following directory: "%directory%"
- ren %rename_what_path% %rename_to%
- if not %errorlevel%==0 (
- echo There was a problem renaming the file.
- ) else (
- echo Renaming was successful.
- )
- echo Errorlevel: "%errorlevel%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement