How to determine file type in Lisp

Viewed 124

Is there anything like file in shell for lisp to determine file type? If not, how do you determine file tpye?

In most case pathname-type is good enough, but sometimes you may run into some files doesn't have been correct named.

1 Answers

The functionality of file is available in libmagic:

As of version 4.00 of the Ian Darwin/Christos Zoulas version of file, the functionality of file is incorporated into a libmagic library that is accessible via C (and C-compatible) linking;[7][8] file is implemented using that library.

Wikipedia

And there is a binding for Common Lisp.

I had to install libmagic-dev on my system, and then:

CL-USER> (ql:quickload :magicffi)
... 
(:MAGICFFI)

CL-USER> (magicffi:pathname-mime #P"/bin/ls")
"application/x-sharedlib; charset=binary"

See MAGICFFI.

Related