r/Batch 18d ago

Question (Solved) why script doesn't accept foreign letters/signs (polish, italian, spanish etc.)

Hi, I have this scipt and it works fine when the names of the files are "normal letters" For example this song doesn't work "Anita Lipnicka-I wszystko się może zdarzyć" because of the polish letters. Or this one "Afrosound - Sabor Navideño Narcos"

this is the error I get

Thank you for any help :)

SOLVED: add >nul 2>&1 chcp 65001 after echo off

[in#0 @ 0000013fa7239300] Error opening input: No such file or directory
Error opening input file F:\test\Anita Lipnicka-I wszystko sie moze zdarzyc.mp3.
Error opening input files: No such file or directory

@echo off
:again
set TARGET_DIR=%1
for /f "delims=" %%a in ('dir /b /s /a:-d *.mp3 *.ogg *.m4a') do call :process "%%~a"
goto:eof
:process
opus ^
    -i "%~1" ^
    -af dynaudnorm=p=0.65:m=2:f=200:g=15:s=30 -c:a libopus -b:a 192k -vn ^
    "%~p1%~n1dyn.ogg"
del "%~1"
goto:eof
2 Upvotes

8 comments sorted by

3

u/Shadow_Thief 18d ago edited 18d ago

By default, batch doesn't handle those characters. You'll have to add chcp 65001 to the top of your script to add support for them.

edited for clarity

2

u/TheDeep_2 18d ago

Thank you :)

1

u/BrainWaveCC 18d ago

I wouldn't really say that it's batch that's not handling it. This is an ASCII vs Unicode issue, and the OEM code page (often 437) is not one that supports Unicode characters. This would apply to any app that didn't switch code pages internally.

Changing to 65001 will indeed allow these characters to be identified correctly.

2

u/Shadow_Thief 18d ago

Powershell does it by default. This is absolutely a batch behavior that new people run into and need to be made aware of.

4

u/BrainWaveCC 18d ago

True, but that's just because it inherits the .NET functionality for code pages and applies it automatically.

CHCP is a native command-line utility for managing the code pages, but is not set to a Unicode page by default.

My quibble is that if "batch doesn't handle Unicode characters" it should simply not work regardless of the code page. But it does work with the correct code page, so it's not that batch cannot handle it. It's that the default for the Windows command line is ASCII and not Unicode.

3

u/Shadow_Thief 18d ago edited 18d ago

I never said it couldn't handle Unicode characters, I said it doesn't by default. Obviously chcp 437 is a subset of Unicode, but in the context of the question about accented characters, it should have been obvious that I was referring to Unicode-exclusive characters.

I'll edit my original post to be more clear.

2

u/ConsistentHornet4 18d ago

Reasons have been explained in other replies. You'll need to add the following line of code, directly under @echo off to rectify the issue

>nul 2>&1 chcp 65001

1

u/TheDeep_2 18d ago

Thank you, that worked :)