Identifying File type by reading files

Nicolas Favre-Félix n.favrefelix at _free.fr
Sat Dec 27 05:44:04 EST 2003


Try to get the source code of the GNU program 'file'.
I give you some examples : 

$ file sqlite.bin
sqlite.bin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for
GNU/Linux 2.2.5, statically linked, stripped

$ file doc.pdf
doc.pdf: PDF document, version 1.4

$ file archive.tar.gz
archive.tar.gz: gzip compressed data, from Unix

$ file music.mp3
music.mp3: MP3, 128 kBits, 44.1 kHz, JStereo

If you plan to run your script in a UNIX environment, maybe you can look
this way, but if it must be portable, you can compile different versions of
file.c to be called with popen. 
Or if you feel having a lot of free nights to spend on it, you can study the
C source code and convert it to Python.

Good luck!





More information about the Python-list mailing list