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

I have existing zip files created by a vendor supplied application. It generates directories of data, in the Zip file, and the directory names are long strings of arbitrary characters. Even though the directories have files in them, I want to delete certain directories as well as the files included within. An example directory:
"MyLabNotebook/Default/{A8C57B20-DFBD-492D-A4F7-B83D84D18CDA}"
The POD for Archive::Zip says it can be done but, I've searched the web and PerlMonks.org and and have yet to come up with a way to do it. I've tried a few ways and nothing seems to work.

I would settle for just renaming the directory and then delete them manually if I had to, but despite what it says in the POD, I can't seem to rename them either.

Any help would be greatly appreciated.

Thanks,
  EigenFunctions
  OpSys: Win7 Professional/Home Premium x64 Service Pack 1

Replies are listed 'Best First'.
Re: Remove an existing, non-empty, directory re: Archive::Zip
by stevieb (Canon) on Aug 15, 2016 at 23:35 UTC

    File::Path's rmtree() may be of help here:

    use warnings; use strict; use File::Path qw(rmtree); my $dir = 'example'; rmtree $dir or die "can't remove the damned dir $dir!";

    I'll leave it up to you to get the directory names and then use rmtree() in a loop.

      The problem is, the directory tree is in a ZIP file (one zip file of many), not on the HDD/SSD.

      Thanks,
        EigenFunctions
        OpSys: Win7 Professional/Home Premium x64 Service Pack 1

        Hello EigenFunctions,

        You can do this with the Archive::Zip->updateTree method, if you have a copy of the archive’s tree on disc, and you first delete the given directory from that copy:

        $zip->updateTree ( { root => 'New_Tree', # On disk zipName => 'Tree', # In the archive mirror => 1, # Delete missing directories and fil +es } ) == AZ_OK or die 'update error';

        But I guess that misses the point of your question, which is, I take it, to delete the given directory directly.

        The POD for Archive::Zip says it can be done...

        Where in the POD do you see that? (Not saying it isn’t there, only that I haven’t found it.)

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Remove an existing, non-empty, directory re: Archive::Zip
by Anonymous Monk on Aug 16, 2016 at 00:48 UTC

    Hi,

    So you have code? can I see ?