Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Simplified issue:

I have a file called Bíblia sagrada.exe (note the í) on C:\ of my computer.

When I open a command prompt on C:\ and execute dir /b /on B*.*, it will return:

Bíblia sagrada.exe

i.e., no issues with diacritic symbols.

But when I do dir /b /on B*.* > c:\a.txt and open c:\a.txt with Notepad, it becomes:

B¡blia sagrada.exe

i.e., it replaces í with ¡.

And if I perform for /f "delims=" %i in ('dir /b /on B*.*') do %i > %i.txt it puts the correct name in the filename but inside it the text is still wrong, i.e.,

Filename:

Bíblia sagrada.exe.txt

Contents:

B¡blia sagrada.exe

What's going on?

PS:

Real issue

The issue for me is worse than I reported on first edit, because I read the contents of a txt file to create a .vbs script and then to execute it; when trying to execute, "it doesn't understand" that it points to "Bíblia sagrada.exe" and it does not execute the program... i.e., I created a .bat on d:\atalhizador\atalhizador.bat:

@echo off

::locais
set drvbak=
set drvprogrs=
set pathbak=%cd%
set pathabove=
set pathprogrs=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

::identificador da pasta do programa no menu iniciar
set id=_pext1

::determina drives de acordo com paths
for /f "delims=" %%z in ("%pathbak%")    do set drvbak=%%~dz
for /f "delims=" %%z in ("%pathprogrs%") do set drvprogrs=%%~dz

::pega caminho superior
cd..
set pathabove=%cd%
cd %pathbak%

cls
echo.***************
echo.* ATALHIZADOR *
echo.***************
echo.
echo.Deseja realmente executar o atalhizador para a pasta:
cd..
echo.  %cd%
cd %pathbak%
echo. [s/n]:
set /p ___o=
if not "%___o%"=="s" if not "%___o%"=="S" goto end

echo.
echo.Criando os atalhos...
for /f "delims=" %%a in ('dir /b /ad /on ..') do (
  echo.- pasta "%%a"...
  echo.  ^|-- buscando arquivos atalhizaveis...
  if not exist "temp" mkdir "temp"
  dir /b /on "..\%%a\*.exe" 1>temp\busca.txt 2>temp\erros.txt
  for /f "delims=" %%b in (temp\busca.txt) do (
    echo.      ^|-- criando atalho para %%b

    for /l %%z in (1,1,1) do set __temp__=

    if not exist "%pathprogrs%\%id%" mkdir "%pathprogrs%\%id%"
    if not exist "%pathprogrs%\%id%\%%a" mkdir "%pathprogrs%\%id%\%%a"

    echo.Set oWS = WScript.CreateObject^("WScript.Shell"^) > temp\%%~na-%%~nb.vbs
    echo.sLinkFile = "%pathprogrs%\%id%\%%a\%%b.lnk" >> temp\%%~na-%%~nb.vbs
    echo.Set oLink = oWS.CreateShortcut^(sLinkFile^) >> temp\%%~na-%%~nb.vbs
    echo.oLink.TargetPath = "%pathabove%\%%a\%%b" >> temp\%%~na-%%~nb.vbs
    echo.oLink.Save >> temp\%%~na-%%~nb.vbs

    cscript /nologo temp\%%~na-%%~nb.vbs
  )
)

:end
%drvbak%
cd %pathbak%

pause
@echo off

The mentioned "Bíblia sagrada.exe" is in d:\Bíblia sagrada.

The generated .vbs file is below (suppose that there are only these two directories on d:), with filename D:\atalhizador\temp\Bíblia Sagrada-Bíblia Sagrada.vbs:

Set oWS = WScript.CreateObject("WScript.Shell") 
sLinkFile = "C:\Users\Ubirajara\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\_pext1\B¡blia Sagrada\B¡blia Sagrada.exe.lnk" 
Set oLink = oWS.CreateShortcut(sLinkFile) 
oLink.TargetPath = "D:\_pext1\B¡blia Sagrada\B¡blia Sagrada.exe" 
oLink.Save 

The issue? The shortcut isn't created because it does not recognize "sLinkFile = "C:\Users\Ubirajara\AppData\Roaming\Microsoft\Windows\Start Menu\Programs_pext1\B¡blia Sagrada\B¡blia Sagrada.exe.lnk"".

It doesn't happen if I don't use diacritics, but really I have a lot of folders and files with that signals...

How to correct it to allow correct writing on .vbs file?

PS2:

I tried following commands, alone and together, with no success:

cmd /u

chcp 860

chcp 1200

mode con cp select=860

mode con cp select=1200

Also I tried it with cmd raster font and with other available fonts...

share|improve this question
    
make sure you add a font that supports it. stackoverflow.com/questions/9321419/… e.g. Courier New , and download DejaVu Sans Mono and Droid Sans Mono you can add those 3. The latter two would have to be downloaded if you want them. – barlop May 18 at 9:08
up vote 1 down vote accepted
+100

Setting the codepage to UTF-8 should help :

chcp 65001

The dir result will then be encoded in UTF8.

If VBS cannot understand it as-is, for the file to be automatically recognized under Windows as UTF8 you will need to prefix it with the UTF8 BOM bytes :

0xEF, 0xBB, 0xBF

You can then start with a file containing the BOM and append to it rather than write :

chcp 65001
copy EFBBBF.txt a.txt
dir /b /on B*.* >> a.txt

Or you may use copy /b to concatenate the files.

share|improve this answer
    
Though chcp 65001 crashes the c# compiler. I suppose not that it matters much unless they were runnign the c# compiler in that shell. see "added 2" in question here stackoverflow.com/questions/30956834/… – barlop May 18 at 9:52
    
also, specifically one would want to change the codepage for the output redirection. chcp changes both and with no parameters displays the input encoding. A program that shows and allows changing of either encoding is chcpa sourceforge.net/p/chcp-advanced/discussion/general/thread/… – barlop May 21 at 23:09
    
I tested chcp and it really crashes cmd, exiting without any error message, when you use, for example, dirafter calling it. But if you redirects output to a file, it is all right, and output file is in UTF8. I tried chcpa, but it is not recognized by Windows 7. – kokbira May 23 at 12:07
    
Now I'm trying the VBS part of issue... – kokbira May 23 at 12:07
    
Although it is not a complete answer, because I cannot solve the VBS part yet (I need to think more), this is the better answer. – kokbira May 23 at 12:24

Notepad is opening your file with the wrong encoding. Try opening using the Open dialog box, and in the bottom selecting other encodings:

Encoding selection

Note that Microsoft uses non-standard names for the encodings. "Unicode" is actually UTF-16LE, and "Unicode big endian" is actually UTF-16BE.

share|improve this answer
    
See my edit :) the issue is worse I written... – kokbira Aug 22 '12 at 22:44
    
Opening as you suggested also do not solve the "display issue". On ANSI, the same issue occurs; on Unicode and Unicode big endian, no alphabet characters are shown; on UTF-8, it replaces ¡ with , but not with í... I.e., correct encoding "may be lost" :( – kokbira Aug 23 '12 at 13:08
    
@kokbira if notepad can't open it even with a font that should show it and even when you know you're opening it with the appropriate encoding matching a unicode bom if there is one,then maybe it wasn't written into the file correctly.U could try deleting all characters other than the funny one then using xxd to see how the character is written into the file, you may find something encoded it wrongly. e.g. something used a font that didn't support it and it replaced that char with another and encoded some other character in its place. Notepad was then not at fault when the wrong char was shown. – barlop May 18 at 9:58

You can circumvent the issue by adding /X to all DIR commands.

That will give you the 8.3 short name (DOS-name) of all files; all further operations are valid with this name, and it will not have any of the UTF issues.

share|improve this answer
    
maybe but can you elaborate what 8.3 has to do with UTF? – barlop May 21 at 18:22
    
The 8.3 name has no special characters or diacritics, so there would be no issues between different programs that use different UTF codings – Aganju May 21 at 19:13
    
I notice that if I do dir 2012*.* /x then up comes the full name(longer than 8.3). And also if I do dir א /x then it still shows that character. So I don't think /x is necessarily doing 8.3 or changing characters to be within ascii. – barlop May 21 at 22:03
    
The /X needs to be before the first directory or file, otherwise it will be considered another directory to list. In your first example, it would be DIR /X 2012*.*. – Aganju May 21 at 22:17

To solve the part where wrong font is shown in Notepad you need to use codepage because Notepad use Ansi as default. A better solution is rather using Notepad++ where you can change to the codepage you like and on top of that you could even change to a better shell with support for unicode so that the error doesn't arise to begin with.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .