Detecting type of file in a program
Paul De Bra
debra at alice.UUCP
Sun Feb 5 10:04:15 AEST 1989
In article <192 at henry.ece.utexas.edu> po at volta.ece.utexas.edu () writes:
>In my program, I am using opendir() to read in the names of
>text files from a directory.
>How can I tell whether a file is text or an object file ?
>Is there a better way than using :
> system("file filename > /tmp/tempfile")
The only way is to look at the contents of the file, which is what the
utility "file" does too.
So read a number of bytes from the file, and then guess, depending on what
you see.
Paul.
--
------------------------------------------------------
|debra at research.att.com | uunet!research!debra |
------------------------------------------------------
More information about the Comp.unix.questions
mailing list