[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help with Perl Script

Posted on 2009-04-24
3
Medium Priority
?
187 Views
Last Modified: 2012-05-06
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,
# 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;
    }

Open in new window

0
Comment
Question by:foxhelp
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 24226746
my $product_filename_regex = sprintf("^%s\\.(mar|tst|xxx)", (length($client_id)<=5 ? $client_id."000":$client_id));
 
0
 
LVL 85

Expert Comment

by:ozo
ID: 24226811
length(12345) <= 5, so wouldn't that be
12345000.mar
12345000.tst
12345000.exn
12345000.bbb
12345000.xxx
?

are the possible ids
1000
12000
123000
1234000
12345000
123456
1234567
12345678
?
0
 

Author Closing Comment

by:foxhelp
ID: 31574240
Thank you, that saved me alot of time.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question