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

Author Topic: Batch file to convert unicode text file to ANSI text file  (Read 18822 times)

0 Members and 1 Guest are viewing this topic.

Mat51

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    Batch file to convert unicode text file to ANSI text file
    « on: January 08, 2012, 02:35:27 PM »
    I want a batch code that would convert my list of text files already saved as unicode to ANSI Type.

    Any help on this is much appreciated.

    Also, I thought a way could be to open the unicode text file and write it to an Ansi text file type, howere not sure if this is the right well because I do have
     a list of text files, i want to convert to Ansi text file type.

    See the code below, it isn't giving me my result though....


    echo off

    $file = FileOpen("C:\Examplle.text", 0)  ; Open for Reading
    $file1 = FileOpen("C:\Example.text", 1) ; Open for Writing


    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf


    If $file1 = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

     
    While 1
        $chars = FileRead($file, 2)
        If @error = -1 Then ExitLoop
            If ($chars) <> "ÿþ" then
                FileWrite ($file1 , StringLeft ($chars , 1))
     
    EndIf

    Wend

    FileClose($file)
    FileClose($file1)


    Many Thanks

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch file to convert unicode text file to ANSI text file
    « Reply #2 on: January 08, 2012, 03:28:06 PM »
    And here is a nice little function you can call within your batch file if you are using a for loop to get a list of your text files you need to convert.
    http://www.dostips.com/DtCodeCmdLib.php#Function.ToANSI

    Salmon Trout

    • Guest
    Re: Batch file to convert unicode text file to ANSI text file
    « Reply #3 on: January 08, 2012, 03:34:13 PM »

    See the code below, it isn't giving me my result though....


    I'm not surprised. That isn't Windows batch/cmd code - it looks like some language you invented.





    Sirim



      Rookie

      Thanked: 2
      • Experience: Familiar
      • OS: Windows 7
      Re: Batch file to convert unicode text file to ANSI text file
      « Reply #4 on: January 08, 2012, 06:38:55 PM »
      I'm not surprised. That isn't Windows batch/cmd code - it looks like some language you invented.

      I think it's some kind of BASIC; I'm not sure which, though.