1

When running a batch file with a file name containing spanish accent é, I am noticing it does not decode properly and hence the batch does not run. I tried saving the batch file as UTF-8, ASCII or UTF-16LE, but to no avail. Anyways to escape the character in the batch file. hypothetical example is.

inside the batch file:

rename XXXéxxx.pdf AAAéAAA.pdf

Thanks in advance!

Artwire
  • 77
  • 9
  • See [Using another language (code page) in a batch file made for others](https://stackoverflow.com/questions/48981387/) and [CMD Can't read Danish characters when I execute .bat file](https://stackoverflow.com/questions/43046559/). – Mofi Jun 07 '18 at 19:07
  • 1
    Possible duplicate of [Using another language (code page) in a batch file made for others](https://stackoverflow.com/questions/48981387/using-another-language-code-page-in-a-batch-file-made-for-others) – Pajdziu Jun 07 '18 at 19:23

1 Answers1

2

you need to use CHCP

try to ad one of these into your batch:

CHCP 852   > NUL
CHCP 1250  > NUL
CHCP 1252  > NUL
CHCP 1145  > NUL    
CHCP 20284 > NUL

last two are particulary spain based (here is the full list)

CHCP stands for "CODE PAGE" and you just need to place it at the begining of your batch

also note that batch always needs to be ASCII

player0
  • 124,011
  • 12
  • 67
  • 124
  • `CHCP` is the abbreviation of CHange Code Page. Running `chcp` without any parameter displays active code page. Wikipedia article about [character encoding](https://en.wikipedia.org/wiki/Character_encoding) explains that a character is for a computer a series of bits with the values 0 or 1 whereby 8 bits form a byte and it depends on rules how a byte value should be interpreted by a program. Wikipedia article about [code page](https://en.wikipedia.org/wiki/Code_page) lists all code pages with links to pages listing the characters of documented code pages. – Mofi Jun 07 '18 at 19:01
  • by they way, if i manually copy the string into cmd window and execute it, it works fine. – Artwire Jun 07 '18 at 22:13
  • This actually did work!!! Thank you ver much! Here is what I did to fix it. My text file was output from SAS. After finagling with variety of encoding, I managed to get the one that works best. encoding=ANYANSI. After this, I had to play with variety of code pages you listed above. The best one is 1252 for the reason, it accommodates not only a single `, but also ~ above letters that make up spanish accents. I did this in the batch file: CHCP 1252 > NULL (then on the next row was my code that invokes pdf tools, etc.). Thanks again for your help! – Artwire Jun 07 '18 at 23:33
  • "batch always needs to be ASCII": `echo ¡No, it doesn't!` ASCII wasn't even a separate codepage until very late. – Tom Blodget Jun 08 '18 at 23:30