[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

equivalent of unix "file " in ruby?

Ruby Rails

10/10/2006 6:13:00 PM

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

--
Posted via http://www.ruby-....

5 Answers

khaines

10/10/2006 6:49:00 PM

0

Gavin Kistner

10/10/2006 7:10:00 PM

0

Ruby Rails wrote:
> 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}`

Austin Ziegler

10/10/2006 7:20:00 PM

0

On 10/10/06, khaines@enigo.com <khaines@enigo.com> wrote:
> On Wed, 11 Oct 2006, Ruby Rails wrote:
> > 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.

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
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Ara.T.Howard

10/10/2006 8:02:00 PM

0

Austin Ziegler

10/11/2006 12:15:00 AM

0

On 10/10/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> http://rubyforge.org/projects/libm...

Yes. Filemagic only binds to the existing libmagic, which still
doesn't help much for Windows users.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca