HamNRye has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I am writing a script that we will use to verify that all of the files in a folder meet our naming conventions before being burned to a cd. One of our biggest problems is a large number of Mac users who place files on this server with no file extension. These files are a combination of Images, layout docs (.qxd, .indd), and text. What I am looking to do is be able to type the file from within perl so I can put a 3 letter extension on it.

I can use the "identify" command with imagemagick, but it does not handle the layout docs.

Anyone know where I can A) find a module that does this all for me, or B) know where I can find the information to roll my own.

Thanks!

Replies are listed 'Best First'.
Re: Using Magic Numbers
by artist (Parson) on May 07, 2003 at 15:55 UTC
Re: Using Magic Numbers
by kilinrax (Deacon) on May 07, 2003 at 15:59 UTC

    There's always the unix utility 'file', which unfortunately doesn't seem to have a CPAN equivalent (unlike quite a few other unix file utilities). Maybe this is something worthy of consideration?

    Update: I thought one didn't exist, having never encountered one, none turning up on a CPAN search, and none being registered in the File:: namespace. Obviously, I was wrong. Use File::MMagic as artist suggests ;)

      IIRC, Dominus wrote a Perl implementation of "file" for Tom's "Perl Power Tools" project. If I were to ever do what the OP is doing, I'd settle for `file $file`, and modifying /etc/magic if needed.

      Abigail

      I should mention this will be on Windows, not the annointed Unix which sprung from the womb of the virgins fully formed.

      Artist, looks like File::MMagic will work for me. Thanks dude.

        No problem, HamNRye, Perl doesn't discriminate against less capable systems. :)

        For what it's worth, File::MMagic's built-in magic file doesn't seem to include support for Macintosh binary, but all is not lost. Grab this file and pass its pathname to the File::MMagic constructor and it will most likely work (untested on Macintosh files, since I have none to test with at the moment).