Windows CMD - Setar String with Accentuation

2

I'm trying to create a Batch (CMD) in Windows that "sweeps" folders in a certain directory and then renames the sub-folders according to a criteria I set.

I'm using the code below to perform the operation (detail: this code I found on the internet and made some small adjustments).

    FOR /D %%D IN (C:\Users\meuUsuario\Desktop\Music\*) DO CALL :RENAME "%%D"
pause

:RENAME
SET CRITERIA=\"(Músicas)"
FOR /D %%R IN (%1%CRITERIA%) DO RENAME %%R "(Singles)"

If I change my criteria to some folder that the nomenclature does not have accentuation, it works normally.

I have been able to solve this for a while, but it's difficult ...

    
asked by anonymous 26.07.2016 / 14:01

2 answers

4

The likely problem is that when saving the file, the correct encoding was not chosen.

The first step is to know the correct encoding by typing the command chcp in the console:

Onmostsystems,thereturnwillbe850.ThesolutionistouseacodeeditorthatallowsyoutosaveinthecorrectCodepage.

AsyoumentionedthatyouhaveNotepad++,thisoptionisfoundinthe

(If not 850, you need to find the most appropriate option in the menu)

A good dash to see if the file was in order after the edit, it is in the CMD itself to execute:

type arquivo.bat

and check that the accented characters appear correctly.

Basically I have formalized the steps that were indicated in separate comments, to eventually help someone with similar problems.     

26.07.2016 / 16:09
1

As @Bacco said, it may be a problem with encoding. One time ago I had this problem, which still generated new .bat from another .bat , to solve I changed to Windows-1252 , adding the command below in the first line:

chcp 1252

Or to convert:

CMD / U / C type ascii.txt > unicode.txt
    
26.07.2016 / 14:30