[lug] C(++) library to detect file type (a la 'file')

Scott A. Herod herod at dimensional.com
Thu Oct 31 21:24:29 MST 2002

rm at fabula.de wrote:
> What do you mean by 'system call' ? I know of no kernel routine that
> does file type guessing. Or are you refering to perl's
> 'system("file $myfile")' function? That's not really an option since
> it spawns a shell which then spawns the 'file(1)'application ...
> nothing one would want to do when indexing a largish set of documents ;-)
> (currently ~ 100 000 docs).

Yes, like the perl system call (you would probably want 'popen' which
creates a return pipe for you).  But, as you note, that would be fine
for one file but not 100k.  Actually, doing 100k file opens is going to
be painful enough as it is.  Since the file command can take multiple
files and even read from standard in, it might not be such a bad
solution, i.e. let the file command deal with opening all of the files.


More information about the LUG mailing list