Solved

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

Posted on 2008-09-29
5
340 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
  • 2
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
Comment Utility
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
Comment Utility

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
Comment Utility
Thanks much!!!!! That did the trick! :-)
0
 

Author Comment

by:taagangel
Comment Utility
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
Comment Utility
No problem about the points - but you can split the points among multiple correct answers.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now