Domanda

In a batch, specifying a path whose name contains an accented character, files are not being found into the file System while stripping out all accented character in the path, these files are found. Nevertheless, I have to manage paths written with accented character. Is there any way to solve this issue?

If you need to know my OS, I'm on SEVEN 32.

Thanks

È stato utile?

Soluzione

Batch by default configuration can't print unicode characters but CAN recognize that chars and use it. That means you can't print "ú" but you can acces to a folder called "ú" or touch a file called "ú".

Then if your script fails to acces a file with accented characters maybe the reason is because the encoding of your script is not ANSI, so open the script in notepad and ensure to save it with ANSI encoding (no utf-8 or unicode).

Example:

@echo off

CHCP 850 >NUL

for %%# in (*.txt) do (

    Echo [+] reading File: .\%%~nx# | MORE
    Type "%%~nx#"
) 

Pause>NUL

Output:

[+] reading File: .\áéíóúàèìòù ñ Ñ ç Ç.txt

This is the text content of my file with ISO-Latin characters

If you want to print accented characters in CMD then you need to make the char conversion, this can do the trick:

@echo off
CHCP 850 >NUL
copy con Mychars.txt

In that prompt you will write the characters you want, for example "éíóú", then you will get a "Mychars.txt" textfile with this content:

 ‚¡¢£

Now you can use that chars to print the accented chars:

@echo off
echo ‚¡¢£
Pause>NUL

Output:

éíóú

PS1: Remember to do all the things that I said saving the script in ANSI encoding.

PS2: Notice how I'm using CHCP 850 command, that means the codepage of the CMD, By default CMD uses the 850 codepage but I launch the CMD with a default 1250 codepage to avoid all those problems so in my examples I needed to use codepage 850 to show you.

You can set the default CMD Codepage with a registry key:

REG ADD "HKCU\Software\Microsoft\Command Processor" /V "Autorun" /T "REG_SZ" /D "chcp 1250 >NUL" /F >NUL 2>&1

And you can read about the codepages here: http://msdn.microsoft.com/en-us/library/cc195064.aspx

Altri suggerimenti

This doesn't work:

@echo off
start "" "C:\Users\dmb3419\Documents\dev\ééééééééé"

This works:

@echo off
chcp 1252
start "" "C:\Users\dmb3419\Documents\dev\ééééééééé"

I had a similar problem with French accents in pathnames using a .bat and xcopy.

using:

@echo off
chcp 1252

handled this for me and the accents were correctly recognised in the .bat file. running under MS server2012 R2 cmd.exe

Please, see below how your tip solved my problem without mixing it with alien code:

CHCP 1252
call "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" "Z:\CYRO\ARTE\ArteRH Dicionário de Dados.xlsx"
call "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" "Z:\CYRO\ARTE\Unificação\01 - MATERIAL APOIO\PADRAO_TABELA_CONVERSAO.xlsx"

Hope it can help somebody else!
Best regards.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top