Hi Monks,
Firstly, I sincerely apologize for the big context
I'm struck up with an issue which I have no idea of why it occurred all of a sudden! The below code was working good until yesterday.
My requirement was :
- Get the compressed folder (zip) or a plain folder as an argument
- if the argument passed is a zip file, then it should extract the contents of the zip in the current directory.
- There is a problem in this case. When the Compressed file is zipped from a folder, it is extracting the content inside a folder with the name of zip file. i.e., if the zip file name is test.zip, the files are extracted into /test folder - This is just fine
- But if the zip file is generated from a list of files but not from a folder, then the extraction puts all the files in the current directory
- After the extraction, i have to find a specific file from the extracted folder. The file would be a text file (.txt) and would have the string "index" in the filename.
use Data::Dumper;
use POSIX qw(strftime);
use File::Copy;
if($#ARGV == -1 || $#ARGV != 0) {
die("\nPlease enter the Compressed folder name along with extensio
+n as an argument!\n");
exit;
}
my $compPackage = $ARGV[0];
my $dir = ".";
my $input_dir = '';
if(index($compPackage, ".zip") != -1) {
print "Extracting the ZIP package..\n";
system ("unzip -u $compPackage");
print "Extraction Completed\n";
$input_dir = substr $compPackage, 0, -4;
}
else {
$input_dir = $compPackage;
print "Folder Processed\n";
}
chmod 0755, $input_dir;
opendir D, $input_dir or die "Could not open dir: $!\n";
my @fileName = grep(/index/i, readdir D);
if(index(@fileName, "txt") == -1) {
die("Index file not found / is not valid!.\nPlease ensure the inde
+x file is in the Input folder and with '.txt' extension\n");
exit;
}
The issue :
- The difference in the folder structure of ZIP file.(i.e., files inside a folder or without a folder). I tried putting a temp folder for the extracted files. But that is causing problems when I try to access the extracted files for further processing due to the zip file structure
- The grep function. It was getting the file name until yesterday. Now it returns '0' or '1' according to the presence of the index txt file
Thanks in advance
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.