Computer Hope

Microsoft => Microsoft DOS => Topic started by: Mat51 on January 08, 2012, 02:35:27 PM

Title: Batch file to convert unicode text file to ANSI text file
Post by: Mat51 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
Title: Re: Batch file to convert unicode text file to ANSI text file
Post by: Squashman on January 08, 2012, 03:16:28 PM
http://www.robvanderwoude.com/type.php#Unicode
http://www.dostips.com/DtCodeSnippets.php#Snippets.UnicodeToAnsi
Title: Re: Batch file to convert unicode text file to ANSI text file
Post by: Squashman 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
Title: Re: Batch file to convert unicode text file to ANSI text file
Post by: Salmon Trout 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.




Title: Re: Batch file to convert unicode text file to ANSI text file
Post by: Sirim 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.