1

I have a script which takes two parameters on the command line. One should be the name of an ZIP archive, one must be an excel (XSLX) file. Both parameters must be either relative or full quallified. Ususally I use File::Type to check if a file has the expected format. but for XLSX files the answer is: "application/zip". I know this is right, because XLSX files are zipped, but how can I distinguish if it's a excel file or if the user made a misstake and provided the ZIP Archive as excel. I also found File::LibMagic, but I can't get it running on Windows.

roli
  • 117
  • 9
  • 5
    Given that XSLX is Zip you don't want to distinguish between XLSX and Zip but essentially between two Zip files - one which has the typical files XLSX has (see https://stackoverflow.com/questions/11082278/how-to-properly-assemble-a-valid-xlsx-file-from-its-internal-sub-components) and one which has some other files inside (which you did not specify). Use Archive::ZIP to check the file listing for this. – Steffen Ullrich Aug 25 '21 at 14:57
  • [File::MimeInfo](https://metacpan.org/pod/File::MimeInfo) seems to understand (`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` vs `application/zip`). (Although on Windows it requires a separately installed mime-info database, sorry.) – Jim Davis Aug 25 '21 at 20:42
  • You could try opening it with Spreadsheet::XLSX and catch if it blows up. – simbabque Aug 26 '21 at 16:35

0 Answers0