foxhelp
asked on
Help with Perl Script
I have a directory that has many different types of files but I need the script to zip on 3 files with differnent extensions. For instance, the directory has these file names:
12345.mar
12345.tst
12345.exn
12345.bbb
12345.xxx
but I only want to zip 12345.mar, 12345.tst, and 12345.xxx but with my script it is zipping all 5 files because I reference the client_id which is 12345. The script is attached.
thanks,
12345.mar
12345.tst
12345.exn
12345.bbb
12345.xxx
but I only want to zip 12345.mar, 12345.tst, and 12345.xxx but with my script it is zipping all 5 files because I reference the client_id which is 12345. The script is attached.
thanks,
# Create a zip file with the necessary files.
my $client_zip_filename = File::Spec->catfile($product_dir,
"product",
sprintf("%s.zip",
$client_id));
# We want the files from the product directory that have the name <client>.*
my $product_filename_regex = sprintf("^%s\\.", (length($client_id)<=5 ? $client_id."000":$client_id));
opendir(ZIP_DIR, "$product_dir\\product") or die "cannot open: $!";
my @files_to_zip = map {"$product_dir\\product\\$_"} grep {/$product_filename_regex/} readdir(ZIP_DIR);
closedir(ZIP_DIR);
$cmd = sprintf("\"c:\\program files\\7-zip\\7z\" a -tzip %s %s",
$client_zip_filename,
join(" ", @files_to_zip));
if (system($cmd) != 0) {
printf("Error executing command /%s/ with error = %d\n",
$cmd,
$CHILD_ERROR);
next;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, that saved me alot of time.
12345000.mar
12345000.tst
12345000.exn
12345000.bbb
12345000.xxx
?
are the possible ids
1000
12000
123000
1234000
12345000
123456
1234567
12345678
?