Detecting type of file in a program

David C Lawrence tale at pawl.rpi.edu
Sun Feb 5 01:10:53 AEST 1989


Just something to note here, too, since this is c.u.questions and not
c.u.wizards (wizards already know this).  `file' is a handy utility
for a lot of things, but alas, it is quite easy to trip it up.  For
one thing, it does not know lisp (as indicated on the manual page) and
for another, comments can really screw it up.  In fact, cpp directives
can screw it up too.  I have a programme that starts out with lots of
#defines.  `file' loves to think that it is just ascii text.  Another
programme has a large comment section at the beginning of the form
/*text\n *more text\n */.  This, alas, is just but ascii text to
`file'.  (Aside: I am curious how it determines something is English
text rather than just ascii text.)
 
Another thing that can screw-up `file' is short, tabular information,
as near as I can tell.  I have a README in my bin directory which
consists of the name of each programme, the language it is written in
and a message about what it does.  This is reported by `file' to be
*roff, et al, input.  Similar behavious has been exhibited on other
files.

One thing I -love- file for is reading raster headers; it tells me
useful information in a nice compact way -- size of image, encoding
information (run-time encoded, standard format, etc).
 
For the purposes of the original poster, `file' is a great way to find
scripts and machine executables; don't rely on it for source files,
especially, though.
 
Dave
--
      tale at rpitsmts.bitnet, tale%mts at rpitsgw.rpi.edu, tale at pawl.rpi.edu



More information about the Comp.unix.questions mailing list