Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test if text-file is Unicode?

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
US
I need to convert a Unicode file to ASCII; I found a simple VBScript to do this (see below).

However, I only want to make this conversion if the source file is Unicode. How can I test the file to see if it's Unicode?

Thanks. Here's the script:

Code:
Option Explicit

Dim sSourceFileName 'as String
Dim sTargetFileName 'as String
Dim sText 'as String
Dim oFSO 'as Object = Scripting.FileSystemObject
Dim oFile 'as Object = File

sSourceFileName = "C:\UnicodeFile.txt"
sTargetFileName = "C:\ASCIIFile.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")

'OpenTextFile(source, forreading, createnew, open as Unicode) 
Set oFile = oFSO.OpenTextFile(sSourceFileName, 1, , True) 
sText = oFile.ReadAll
oFile.Close

'OpenTextFile(destination, forwriting, createnew, open as Ascii) 
Set oFile = oFSO.OpenTextFile(sTargetFileName, 2, True, False)
oFile.Write sText
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top