namishtiwari has asked for the wisdom of the Perl Monks concerning the following question:
I am getting the files from ftp site and the files that are zipped ones. I am able to extract them also in the same folder. I need little help in--- The unzipped files which i got, i only need few of them not all. The format of the filename is like this---#!/usr/bin/perl use Net::FTP; use Archive::Zip; use IO::File ; print "Retrieving file from log.abc.com...\n"; $loginip='123.678.90.18'; $loginid='nkt123'; $loginpaswd='12345678'; ($sec,$min,$hour,$mday,$mon,$year)=(localtime(time))[0,1,2,3,4,5]; $time_stamp= "_" . (1900+$year) . "_" . ($mon+1) . "_" . ($mday) . "_" + . $hour . "_" . $min . "_". $sec; printf "time stamp = $time_stamp\n"; unless(-d "temp") { mkdir("temp"); } if( -d "temp") { chdir("temp"); } $ftp = Net::FTP->new(($loginip), Debug => 0) or die "Cannot connect to log.abc.com: $@ \n"; $ftp->login($loginid,$loginpaswd) or die "Cannot login ", $ftp->message; $source_dir="/nt/logs/nali05/"; $ftp->cwd($source_dir) or die "Cannot change working directory ", $ftp->message; $ftp->binary || die "Unable to set mode to binary. ", $ftp->message; @list=$ftp->ls(); printf "list = \n"; print @list; foreach $file (@list) { $ftp->get($file) or die "get failed ", $ftp->message; my $zipname = $file; my $destinationDirectory = 'C:\Perl Script\temp'; my $zip = Archive::Zip->new($zipname); foreach my $member ($zip->members) { next if $member->isDirectory; (my $extractName = $member->fileName) =~ s{.*/}{}; $member->extractToFileNamed( "$destinationDirectory/$extractName"); } #rename($file,"${file}_${time_stamp}"); $ftp->delete ($file) or die "rm -rf failed ", $ftp->message; } #} $ftp->quit;
I get so many files files when i unzip thme , this is just a sample. In these two files i want the files which contains web in that and delete the rest from the folder. And one more help i need is this-- We get 4-5 log files for a day with the fromat above. There will be files older than today also, i want to run my script for today's logs only. Thanks NTrisk_14Jul09_16_10_48.log web_14Jul09_16_10_48.log
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chosse selected files and delete rest
by jrsimmon (Hermit) on Jul 28, 2009 at 15:02 UTC | |
by Bloodnok (Vicar) on Jul 29, 2009 at 08:52 UTC |