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

Text/Binary File Identification

0 views
Skip to first unread message

Michael Kroh

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to

Hi all. This may sound kinda' basic, but suppose you want to be able to
tell whether or not a file is a text or a binary (regardless of filename
extension) and then, if text do one thing, if binary do another, etc.
etc.?

Thank you for any help...

Michael Kroh

kr...@mail.utexas.edu

Thoralf Nordtømme

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to

Michael Kroh wrote:
>
> Hi all. This may sound kinda' basic, but suppose you want to be able to
> tell whether or not a file is a text or a binary (regardless of filename
> extension) and then, if text do one thing, if binary do another, etc.
> etc.?
>
Hi Michael,
here's what I do:

Open the file in Binary and check if any of the first, say 255
characters, are not printable, i.e in the range {0:6;14:31}
If not in range, assume the file is binary, else it's probably text.
--

Thoralf

Private: mailto:thor...@online.no http://home.sol.no/~thoralfn/
At-Work: mailto:th...@atex.no http://www.atex.no

My reply-address is made-up to avoid junk-mail, please use the address
above!

Lee J. Weiner

unread,
Oct 16, 1997, 3:00:00 AM10/16/97
to

In article <3445D4...@mail.utexas.edu>, Michael Kroh <kr...@mail.utexas.edu> wrote:
>Hi all. This may sound kinda' basic, but suppose you want to be able to
>tell whether or not a file is a text or a binary (regardless of filename
>extension) and then, if text do one thing, if binary do another, etc.
>etc.?

Other people may have other rules, but generally a text file is one which does
not contain any characters outside the range ASCII 32 to ASCII 127 (with the
possible exception of ASCII 9, the Tab character). Therefore, open the file
for binary, read the whole file into a string variable (or read it in in
chunks if it's too large for a single variable) and use Instr to examine the
bytes in the variable to see if you find any characters outside the range.

Lee Weiner
weiner AT fuse DOT net

VBDis

unread,
Oct 18, 1997, 3:00:00 AM10/18/97
to

Im Artikel <3445D4...@mail.utexas.edu>, Michael Kroh
<kr...@mail.utexas.edu> schreibt:

>if text do one thing, if binary do another, etc.

If binary, you must exactly know how to handle the contents of the file.
This obviously includes the knowledge about the structure of the file, so
you'll easily find out how to answer your question ;-)

DoDi

K. McCracken

unread,
Oct 20, 1997, 3:00:00 AM10/20/97
to

In article <3445D4...@mail.utexas.edu>, Michael Kroh <kr...@mail.utexas.edu> wrote:
>Hi all. This may sound kinda' basic, but suppose you want to be able to
>tell whether or not a file is a text or a binary (regardless of filename
>extension) and then, if text do one thing, if binary do another, etc.
>etc.?
>
>Thank you for any help...
>
>Michael Kroh
>
>kr...@mail.utexas.edu

As I recall, most binary files contain ASC(0) characters whereas pure text
files normally do not.

0 new messages