How to treat accentuation in. bat files?

Asked

Viewed 23,430 times

10

good morning!

I’m having a hard time copying a file from one folder to another via the copy command.

I’m using the Encoding UTF-8, but the cmd can’t handle the accentuation for the line below:

copy "C:\SVN\Makro\Templates e Orientações operacionais\02 - Templates da Fábrica de Testes\FTMakro - MKRXXXXXX - QA de EFN.xlsx" "C:\SVN\Makro\Demandas\Fábrica Não Definida\EFN_%NomeDemanda%\01_Artefatos_de_Entrada_e_QA\FTMakro - %NomeDemanda% - QA de EFN.xlsx"

And returns the error:

C:\SVN\Makro\Demandas\Fábrica Não Definida\EFN_za>copy "C:\SVN\Makro\Templates e Orienta?º?Áes operacionais\02 - Templates da F?íbrica de Testes\FTMakro - MKRXX XXXX - QA de EFN.xlsx" "C:\SVN\Makro\Demandas\F?íbrica N?úo Definida\EFN_za\01_A rtefatos_de_Entrada_e_QA\FTMakro - za - QA de EFN.xlsx" O sistema não pode encontrar o caminho especificado.

Please, can you help me solve the deal? Thank you.

  • use an ASCI II character table, that’s what solved my problem

4 answers

13

Perform two simple steps:

  1. Save the file . bat with UTF-8 charset
  2. Specify the charset inside the file . bat using the command chcp (Change Code Page). For UTF-8, the code is 65001

Example

foo bat.

chcp 65001
copy "C:\ação.txt" "C:\ação3.txt"

In Windows CMD, just call . bat normally.

C:\>foo.bat

If the CMD screen is not displaying the characters correctly, check the font type that is configured.

Right-click the top bar of the window and select "Properties" (Properties). Choose a UTF-8 compatible font.

  • With chcp 65001 worked perfectly.

5

You can overwrite the full path to the file "short path" short path, so that DOS can understand.

You can use the command:

for %I in (.) do echo %~sI

Upshot

C: Users ADMINI~1 Desktop

dir /x

To identify the short path of the file.

Example:

18/11/2015 15:42 13.948 ALTER_~1.ODT alter_database_character_oracle . odt

10/02/2014 09:23 168.506 CODIGO~1.PDF Codigodeeticaecondutadalg.pdf

18/11/2015 15:42 8.095 COMAND~1.SQL Commands_oracle.sql

02/08/2013 18:38 708.096 ORCAME~1.DOC Budget Personal.doc.

21/07/2015 09:33 1.039 SQLTOO~1.LNK Sqltools 1.7.lnk

Ai just catch the short path.

C: Users ADMINI~1 Desktop ALTER_~1.ODT

  • Hoppy, thank you for the direction. I was able to absorb the context, but I still can’t figure out how to apply the short path.

  • enters the folder where the file is by DOS and type the command: "for %I in (.) echo %~si" the result will be the short path of the folder, now type "dir /x" you will get the short path of the file. joining the 2, you have the full file path.

  • Ah, great! Thanks! I’ll try here.

  • comments on the result, then. hugs!

  • It worked out! Thank you, Hoppy! The short path, folder to folder must be used.

  • each folder has its shortpath set. you can also use this command to get the full file shortpath: "cmd /c for %A in ("C: Documents and Settings User NTUSER.DAT") from @echo %~sa"

Show 1 more comment

3

Just enter this code at the beginning of your . bat

@CHCP 1252 >NUL
  • It worked for me, but what does this chunk of code mean? It seems that ">NULL" is the key to the magic happening.

  • From what I understand it is to hide the outputs of the command https://answall.com/questions/148701/como-concealr-a-sa%C3%Adda-de-comando-no-cmd

2

You don’t need all that red tape if you want to say a word accented inside a batch file, just do the following:

1 - on the desktop, hold SHIFT, right-click on an empty field, go to "Open Command Window here"

2 - type: Echo."Accented word">word.txt

3 - Open the file "word.txt" and have the word with the character of accent corrected, done this just copy the word into the Batch that it will already show the word with accent.

BS: In "Sharp Word" put the word you want accentuate, no need to quote

  • It’s more boring to do, but it worked for me. Tks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.