Solved

excluding a subdirectory in a perl script that uploads images to an ftp site

Posted on 2008-09-29
5
348 Views
Last Modified: 2010-04-21
I am dealing with a perl script that runs on a cron to ftp images from one server to another via ftp. Currently the image directories are /listings/residential    /listings/commcercial and so on... each of these directories has a subdirectory for thumbnails... as the script stands now, it ftps all the images and as a result the thumbnails end up overwriting the full size images... Can i easily add to the following code to exclude any subdirectory with the name 'thumb' or thumbnails?
here's the ftp portion of the code:


open(IMG, "< $filelist") or die "$!";
while($file=<IMG>) {
	chomp $file;
	$rs = $ftp->put($file);
	if($rs ne ''){
		&log(sprintf("FTP PUT FILE: %s", $rs));
	}else{
	 	&log(sprintf("FTP PUT ERROR: %s", $file));
	}
}
close(IMG);

Open in new window

0
Comment
Question by:taagangel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22598231
try:

open(IMG, "< $filelist") or die "$!";
while($file=) {
      chomp $file;
    if( $file !~ m/thumb/i)
    {
      $rs = $ftp->put($file);
      if($rs ne ''){
            &log(sprintf("FTP PUT FILE: %s", $rs));
      }else{
             &log(sprintf("FTP PUT ERROR: %s", $file));
      }
     }
}
close(IMG);
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22598256

open(IMG, "< $filelist") or die "$!";
while($file=<IMG>) {
        chomp $file;
        next if $file =~ /^thumb(nails)?$/i;
        $rs = $ftp->put($file);
        if($rs ne ''){
                &log(sprintf("FTP PUT FILE: %s", $rs));
        }else{
                &log(sprintf("FTP PUT ERROR: %s", $file));
        }
}
close(IMG);

Open in new window

0
 

Author Closing Comment

by:taagangel
ID: 31501250
Thanks much!!!!! That did the trick! :-)
0
 

Author Comment

by:taagangel
ID: 22598343
Thank you! Another person posted a very similar answer before you did and that one worked. Wish I could give you some points though as yours looks like it would have worked as well.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22598375
No problem about the points - but you can split the points among multiple correct answers.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

624 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