Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Problem: Dir output to file  (Read 2776 times)

0 Members and 1 Guest are viewing this topic.

Overkill

    Topic Starter


    Newbie

    Problem: Dir output to file
    « on: February 14, 2010, 01:37:10 AM »
    I'm writing a program that utilizes the DIR command with the windows XP command prompt and ran into a problem...

    One of the directories contains the character "é" (ALT + 130) and when I output to screen it prints fine, but when I try to dump the result to a file the "é" is changed to a comma.

    C:\Example> dir "*é*" /b
    C:\Example\Foldér

    C:\Example> dir "*é*" /b > list.txt

    C:\Example> more < list.txt
    C:\Example\Foldér

    all seems well, but when i try to view the file with notepad/wordpad or read it with another program, i see this:
    C:\Example\Fold‚r

    It seems that the "comma" character is written in hex as 82 (converts to 130 in decimal which is the alt code) and is being interpreted by the command prompt as é when the character actually written in hex as "E9" (233 in decimal)

    Long story short...without having to hardcode all of the possible exceptions into my program is there a way to get the command prompt to dump the text verbatim?

    Salmon Trout

    • Guest
    Re: Problem: Dir output to file
    « Reply #1 on: February 14, 2010, 03:11:20 AM »
    This is a code page problem. When doing the DIR, the active code page must be one that supports accented characters. I guess your system default is an Anglo-Saxon one that does not? (most likely 850). You can check by issuing the chcp [=change code page] command without a parameter, it will then show the current active code page. To change, use the chcp command with the number of the code page you want. For example chcp 1252 (When I am doing stuff in French or Spanish I use code page 1252 which supports the commonly used accented characters for Western European languages.) See these screen captures. Or you can change the default system code page using the Control Panel, Regional and Language Options, Advanced tab. Plenty of info on the web about what code pages there are.

    E.g.

    http://www.sisulizer.com/support/codepages.shtml#HowToChange





    Overkill

      Topic Starter


      Newbie

      Re: Problem: Dir output to file
      « Reply #2 on: February 14, 2010, 06:18:51 AM »
      That's certainly it; using 437 atm.  Going to write something into the source to save original code page, change to 1252 temporarily, and change back.

      Appreciate the help...glad it wasn't the alternative of spending several hours coding a weak fix.