Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determining if a file is UNICODE or not

871 views
Skip to first unread message

Daren Wilkinson

unread,
Dec 18, 2001, 6:55:54 PM12/18/01
to
Hi,

I am writing a string substitution script, and need it to work on both ASCII
and UNICODE files, and so need to determine if the file has been saved in
UNICODE or not, so that I can then open the input and output files with the
correct TriState values.

Does anyone know how to query a files attributes to determine if a file is
UNICODE or not?

Many thanks,

Daren Wilkinson


Michael Harris (MVP)

unread,
Dec 19, 2001, 11:44:26 AM12/19/01
to
You'll have to open and sniff the file for the presence of a Unicode BOM (Byte Order Mark)...

FAQ - UTF and BOM
http://www.unicode.org/unicode/faq/utf_bom.html


filename = "C:\some path\some file.txt"
set fso = createobject("scripting.filesystemobject")
set ts = fso.opentextfile(filename)
char1 =ts.read(1)
char2 =ts.read(1)
ts.close
if asc(char1) = 255 and asc(char2) = 254 then
msgbox "unicode"
set ts = fso.opentextfile(filename,,,true)
else
msgbox "ascii"
set ts = fso.opentextfile(filename)
end if
text = ts.readall
ts.close
msgbox text


--
Michael Harris
Microsoft.MVP.Scripting
--

"Daren Wilkinson" <daren.w...@roche.com> wrote in message news:e7Qxg#BiBHA.2196@tkmsftngp07...

Daren Wilkinson

unread,
Dec 19, 2001, 12:29:46 PM12/19/01
to
Michael,

Many thanks this works great.

Daren


"Michael Harris (MVP)" <mik...@mvps.org> wrote in message
news:uDo1EyKiBHA.1744@tkmsftngp03...

0 new messages