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