What you’re seeing is
very typical: the command works in an interactive CMD window, but the
.BAT “does nothing” because:
1)
You copied forum formatting into the BAT
This line is
not valid batch syntax:
[USER=35331]@echo[/USER] on
That’s WindowsForum BBCode. In a real
.bat it must be
exactly:
[USER=35331]@echo[/USER] on
(or
@echo off)
2) When you double‑click a BAT, the window often
closes immediately, so you don’t see the error.
You need a
pause or run it from an already-open CMD.
Fix: use this exact BAT (copy/paste)
Open
Notepad, paste this exactly, save as e.g.
test-rename.bat:
Code:
[USER=35331]@echo[/USER] on
setlocal pushd "E:\Downloads\Temp1" || ( echo FAILED: cannot open folder pause exit /b 1) echo Current folder is:
cd echo Listing the exact filename:
dir /b "013 - APOSTA EUROMILHÕES 036 - 05-05-2023 - SEM PRÉMIOS.pdf" echo Renaming...
ren "013 - APOSTA EUROMILHÕES 036 - 05-05-2023 - SEM PRÉMIOS.pdf" "013.pdf"
echo ErrorLevel=%errorlevel% popd
endlocal
pause
Now double-click it. You will
see what fails (folder not found, file not found, access denied, etc..
Very important: save the BAT with the right encoding
Because your filenames contain
á/õ/É etc., Windows 11 Notepad often saves as UTF‑8, and CMD batch files can behave oddly with accented characters.
When you save the
.bat:
- Notepad → File → Save As
- Save as type: All files
- Encoding: choose ANSI (or “Windows-1252” if your Notepad offers it)
- File name:
test-rename.bat
This alone fixes many “works in CMD, fails in BAT” cases with accented filenames.
Also verify you really saved a .BAT (not .BAT.txt)
In File Explorer:
- View → Show → File name extensions
Make sure it is test-rename.bat and not test-rename.bat.txt.
One more quick test (best diagnostic)
Open CMD, go to the folder, and run your BAT from there:
Code:
cd /d "E:\Downloads\Temp1"
test-rename.bat
If it errors, you’ll see the message and it won’t vanish.
If you paste here
the output shown by that BAT (it will list the file, then show the rename attempt + ErrorLevel), I’ll tell you the exact reason it fails on your machine.