Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 29th, 2008, 10:12 AM
murrays murrays is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 murrays User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 21 sec
Reputation Power: 0
Get folder names, FTP

I'm trying to traverse a range of years that correspond to different directories that a user specifies. Within each year subdirectory is a list of folders. I want to be able to get the folder list names into an array and then walk through each subfolder to download the files. Any suggestions on how to do this? I've been struggling trying to use opendir, readdir, and closedir. Also, I do not want to install any additional modules from perl if possible such as File::Find. Thanks.

Reply With Quote
  #2  
Old February 29th, 2008, 02:55 PM
murrays murrays is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 2 murrays User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 21 sec
Reputation Power: 0
In case anyone needs this in the future, this is what I ended up using.


sub download_setfiles
{
$year = $_[2];
$sp = $_[1];
$dir=$_[0];
$ftp->binary();
@months = $ftp->ls(".");
foreach $months(@months) {
$ftp->cwd($months);
@days = $ftp->ls(".");
foreach $days(@days){
$ftp->cwd($days);
@files = $ftp->ls(".");
foreach $files(@files){
if($files =~ m/$sp/) {
$ftp->get($files) or die "Can not download $files\n";
chop($files); chop($files); chop($files);
print LOG "$files\n"; push(@downloadedfiles, $files); }
}
$ftp->cwd("..");
}
$ftp->cwd("..");
}
$ftp->cwd("..");
}

Reply With Quote
  #3  
Old March 6th, 2008, 10:02 AM
agarwalniru agarwalniru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 41 agarwalniru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 37 m 38 sec
Reputation Power: 5
hello,

I am trying to code something similar to urs!!! so neede ur help in this as u have already worked it out.
I need to do ftp files from lan to unix box and then traverese a root directory.
and int hen root directory there are sub folders...and I need to grab all the files in each odf the sub folder and parse the file names to send them to designated folders.

I am using shell script to FTP and then using Perl script to grab the files and parse tehm!!!

can u plz give some suggestion???

Thanks

Reply With Quote
  #4  
Old March 6th, 2008, 08:55 PM
kalyanraj's Avatar
kalyanraj kalyanraj is offline
8 Miles
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: India
Posts: 356 kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level)kalyanraj User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 2 h 2 m 56 sec
Reputation Power: 71
Agarwal,

Please post the code what've you tried so far. Here is a snippet which traverses from root folder to sub folder inside it.

Code:
#!/usr/bin/perl
use strict;

&smash("/archive");
sub smash {
    my $dir = shift;
    opendir DIR, $dir or return;
    my @contents =
        map "$dir/$_",
        sort grep !/^\.\.?$/,
        readdir DIR;
    closedir DIR;
    foreach (@contents) {
        next unless !-l && -d;
        &smash($_);
    }
}


HTH,
Kalyan

Reply With Quote
  #5  
Old March 7th, 2008, 10:32 AM
agarwalniru agarwalniru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 41 agarwalniru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 37 m 38 sec
Reputation Power: 5
Thanks Kalyan.......I will post my code in a while!!!

Reply With Quote
  #6  
Old March 12th, 2008, 10:58 AM
agarwalniru agarwalniru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 41 agarwalniru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 37 m 38 sec
Reputation Power: 5
heers my code .........and this is not working as we cannot use File:Find modulesat work
perl Code:
Original - perl Code
  1.  
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5.  
  6. our $source_dir = shift;    # get input directory name
  7. our $dest_dir = shift;      # get output directory name
  8.  
  9. our @subdirs = ();               # to store the sub directories and their corresponding files
  10.  our $files = undef;
  11.  our @names = ();
  12.  
  13.  our $subdir1 = undef;
  14.   our $subdir2 = undef;
  15.  
  16.  our $quarter_year = 'a';
  17.  our $report_id = 'b';
  18.   our $client_id = 'c';
  19.   our $group_id = 'd';
  20.   our $names1= undef;
  21.  
  22.  $source_dir = "/usr/local/whiecp/bin/crpt/test";
  23.  $dest_dir"/usr/local/whiecp/bin/crpt";
  24.  
  25.  print "source".$source_dir;
  26. print "\n dest = $dest_dir";
  27.  
  28.  @subdirs=find(sub{$File::Find::name if -f && /\.pdf$/}, $source_dir);
  29.  print @subdirs;
  30.         foreach $files(@subdirs) {
  31.                         chomp($files);
  32.                         print $files;
  33.                         $names1 = split(/\./,$files);
  34.                         @names=split(/_/,$names1);
  35.                         $quarter_year= $names[0];
  36.                         print "\n $quarter_year";
  37.                         $client_id = $names[1];
  38.                         print "\n $client_id";
  39.                                 if (/(CL|cl)\.pdf/) {   # This checks the Report_level
  40.                                         $group_id = "";
  41.                                         $report_id = $names[2];
  42.                                 }
  43.                                 else {
  44.                                         if (/(GL|gl)\.pdf/) {
  45.                                                 $group_id = "";
  46.                                                 $report_id = $names[2];
  47.                                         }
  48.                                         else {
  49.                                                 $group_id = $names[2];
  50.                                                 $report_id = $names[3];
  51.                                         }
  52.                                 }
  53.                        print "\n $group_id";
  54.                        print "\n $report_id";
  55.         }
  56. l

Reply With Quote
  #7  
Old March 12th, 2008, 01:23 PM
agarwalniru agarwalniru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 41 agarwalniru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 37 m 38 sec
Reputation Power: 5
i just now found out a solution .....thanks to all of you for your help!!!

Reply With Quote
  #8  
Old March 13th, 2008, 11:08 AM
agarwalniru agarwalniru is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 41 agarwalniru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 37 m 38 sec
Reputation Power: 5
By using the followintg line of code I have been able to get the list of al the .pdf files from aa root directory and its subdirectories.

@filelist=`find $source_dir -name "*.pdf"`;

there are other modules that can be used . but I havd the restriction of not having the rights to download them at the unix server.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Get folder names, FTP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap