How to move accented files using `Batch`?

Viewed 84

If I move an accented file to the same directory using the command prompt, it works correctly.

move ó.mp3 ó.mp3

However, when I use the same command in a .bat file, the following error appears: the system cannot find the file specified.

@echo off
move ó.mp3 ó.mp3
pause
2 Answers

You should change the code page with this command CHCP /?

@echo off
CHCP 65001>nul
move ó.mp3 ó.mp3
pause

A flagrant mojibake case. I guess that you save the script using Windows' native notepad editor using co-called ANSI encoding. The following commented code snippet could enlighten the problem:

@ECHO OFF
SETLOCAL EnableExtensions

REM save current code page (optional)
for /F "tokens=1* delims=:" %%G in ('CHCP') do set "_currentCP=%%H"
REM find notepad's ("ANSI") code page
for /F "tokens=1,2*" %%G in ('
  REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -v ACP^|find "ACP"
') do set "_notepadCP=%%I"

REM show flagrant mojibake case
echo %_currentCP%: move ó.mp3 óó.mp3

REM change the active console code page and show right result  
>NUL CHCP %_notepadCP%
echo %_notepadCP%: move ó.mp3 óó.mp3

REM reurn the active console code page to saved value (optional)
>NUL CHCP %_currentCP%

pause

Result:

D:\bat\SO\61743331.bat
 852: move ˇ.mp3 ˇˇ.mp3
1250: move ó.mp3 óó.mp3

I see above output on my (Central European) Windows. On Western Windows, you could see something like

 850: move ¾.mp3 ¾¾.mp3
1252: move ó.mp3 óó.mp3
Related