Detecting type of file in a program
Leo de Wit
leo at philmds.UUCP
Tue Feb 7 16:08:23 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")
Since Unix does not have the notion of a file type (at least not like
V..) you'll end up doing something equivalent to what 'file' does.
Using file perhaps enhances portability.
Try as a variant:
pp = popen("exec file filename","r");
to get the lines of 'file' into your program (and use 'pclose', not
'fclose' to close the stream). You can even grep for 'text' in the
output from file.
Leo.
More information about the Comp.unix.questions
mailing list