Hi Monks,

I have a requirement to find zip,tar,jar,tar.gz etc.. files recursively in a directory and its sub directories and extract them.After extracting, i need to find a specific file and report its name and size into an xml file.

i am able to write the code to dump the file's size and name to an xml file but i am not able to extract the files recursively and get specified files i need to report in the xml file.

If the file found is a .swtag file,I am storing its size and its contents in a hashreference for later use.

Here is my code using File::Find module.

my $min_depth = 0; find( { wanted => \&wanted, }, @dirs); sub wanted { my $depth = $File::Find::dir =~ tr[/][]; return if $depth < $min_depth; if ( $File::Find::name =~ m/.zip\z$|file.*?\z$|.bak\z$|.jar\z$|.wa +r\z$/g ) { print "I am extracting zip file : $File::Find::name\n"; system("unzip -o $File::Find::name"); } if ( $File::Find::name =~ m/.tar.gz\z$/ ) { &execute_command("tar -xzvf $File::Find::name"); } if ( $File::Find::name =~ m/.iso\z$/ ) { system("mkdir /tmp/mnt"); system("mount -o loop $File::Find::name /tmp/mnt"); my @dirs = ( '/tmp/mnt' ); find ( { wanted => \&wanted, },@dirs ); system("unmount /tmp/mnt"); system("rm -rf /tmp/mnt"); } if ( $File::Find::name =~ m/.SYS$|.sys$|.sys2$|.SYS2$|.cmptag$|.sw +tag$|.swidtag$|.tag$|.fxtag$/ ) { print "$File::Find::name\n"; my $fsize = stat($File::Find::name); $fileparamhash->{$File::Find::name}->{Size} = $fsize->size; if ( $File::Find::name =~ m/.swtag$/ ) { my $parser = XML::LibXML->new; my $doc = $parser->parse_file("$File::Find::name"); my $FileDescription; my $versionname; my @filedesc = $doc->getElementsByTagName("ProductName"); foreach ( @filedesc ) { $FileDescription = $_->textContent; } my @versions = $doc->getElementsByTagName("ProductVersion"); foreach ( @versions) { $versionname = $_->textContent; } $fileparamhash->{$File::Find::name}->{FileDescription} = $File +Description; $fileparamhash->{$File::Find::name}->{FileVersion} = $versionn +ame; } } } }

can anyone look into my buggy code and help me..it is urgent.

Many Thanks, Sriram


In reply to Find files recursively and get their attributes by sriram83.life

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.