|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.
|
|
#2
|
|||
|
|||
|
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(".."); } |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
Thanks Kalyan.......I will post my code in a while!!!
|
|
#6
|
|||||
|
|||||
|
heers my code .........and this is not working as we cannot use File:Find modulesat work
perl Code:
|
|
#7
|
|||
|
|||
|
i just now found out a solution .....thanks to all of you for your help!!!
|
|
#8
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Get folder names, FTP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|