How to handle accent in .bat files?

5

Good morning!

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

I'm using UTF-8 Encoding, but cmd can not handle the accent to line below:

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

And returns error:

C:\SVN\Makro\Demandas\Fábrica Não Definida\EFN_za>copy "C:\SVN\Makro\Templates e Orienta?º?Áes operacionais - Templates da F?íbrica de Testes\FTMakro - MKRXX XXXX - QA de EFN.xlsx" "C:\SVN\Makro\Demandas\F?íbrica N?úo Definida\EFN_za_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 resolve the dispute? Thank you.

    
asked by anonymous 03.12.2015 / 13:41

3 answers

7

Perform two simple steps:

  • Save the .bat file with UTF-8 charset
  • Specify the charset within the .bat file 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 the .bat normally.

    C:\>foo.bat
    

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

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

        
    27.12.2015 / 09:31
    4

    You can replace the full path to the short path for the DOS to understand.

    You can use the command:

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

    Result

      

    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 CODE ~ 1.PDF   CodigodeEticaeCondutadaLG.pdf

         

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

         

    02/08/2013 18:38 708,096 ORCAME ~ 1.DOC Budget of   Personal.doc

         

    21/07/2015 09:33 1039 SQLTOO ~ 1.LNK SQLTools 1.7.lnk

    ai just get the short path.

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

        
    03.12.2015 / 13:52
    2
      

    Do not need so much bureaucracy, if you want to put a word   accentuated within 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. "Keyword" > word.txt

         

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

         

    obs: in "Accentuated Word" put the word you want   accent, no need to have quotation marks

        
    20.04.2018 / 20:51