equivalent of unix "file <filename>" in ruby?

R

Ruby Rails

Hi all,
I'm trying to find out what is the equivalent of file <filename> from
unix in ruby. Basically this command gives the file type - ASCII, BINARY
etc.

Please help!
-Thanks
 
K

khaines

Hi all,
I'm trying to find out what is the equivalent of file <filename> from
unix in ruby. Basically this command gives the file type - ASCII, BINARY
etc.

There is currently nothing written in ruby that uses a library of
signatures to attempt to figure out the file type of a file. The best you
can do right now is a library that looks at the file suffix and determines
what file type matches it.

Download Austin Zeigler's mime-types lib (when Rubyforge is playing nicely
again).

mime_type = MIME::Types.type_for(filename)



Kirk Haines
 
P

Phrogz

Ruby said:
I'm trying to find out what is the equivalent of file <filename> from
unix in ruby. Basically this command gives the file type - ASCII, BINARY

If your program will always run on a system where that command is
available, you could do:
file_type = `file #{filename}`
 
A

Austin Ziegler

There is currently nothing written in ruby that uses a library of
signatures to attempt to figure out the file type of a file. The best you
can do right now is a library that looks at the file suffix and determines
what file type matches it.

That's not *quite* true. I think it's safer to say that there's
nothing currently working in Ruby that does that. However, CRUserS
(the Calgary Ruby Users' Society) is working on a libmagic port to
Ruby as part of an ongoing hacking night. I'm not sure their current
status, and hope that they'll be setting things up to link into
MIME::Types when it's all done, but they are working on it and there
is code in their source repository on RubyForge.

-austin
 
A

ara.t.howard

That's not *quite* true. I think it's safer to say that there's
nothing currently working in Ruby that does that. However, CRUserS
(the Calgary Ruby Users' Society) is working on a libmagic port to
Ruby as part of an ongoing hacking night. I'm not sure their current
status, and hope that they'll be setting things up to link into
MIME::Types when it's all done, but they are working on it and there
is code in their source repository on RubyForge.

there is

http://raa.ruby-lang.org/project/filemagic/

is this their project probably?

http://rubyforge.org/projects/libmagic-ruby/

cheers.

-a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,215
Messages
2,571,113
Members
47,708
Latest member
SharonMaes

Latest Threads

Top