in reply to Need Net::FTP::dir help
sub GetDirHashPtr ( $ ) { # Returns a reference pointer to an array of hashes: # 'Type'=>"Directory|File" # 'Name"=>varies my $DirPath = $_[0]; my @DirArray; my @DirArrayOfHashes; # print "Making directory of $DirPath\n"; @DirArray = @{$ftp->dir ( "$DirPath/.*" )}; push ( @DirArray, @{$ftp->dir ( "$DirPath" )}); # for ( @DirArray ) { print " $_\n"; }; print "\n"; for my $Line ( @DirArray ) { # note: you want everything else at the end my @SplitArray = split ( /\s{1,}/, $Line, 9 ); # print "<$SplitArray[0]> <$SplitArray[8]> \n"; if ( "$SplitArray[8]" eq "\." || "$SplitArray[8]" eq "\.\." ) { # print "Skipping $SplitArray[8] directories\n"; } elsif ( $SplitArray[0] =~ /^d/ ) { # print "Pushing Directory $SplitArray[8]\n"; push ( @DirArrayOfHashes, { 'Type'=>"Directory", 'Name'=>"$Sp +litArray[8]" } ); } else { # print "Pushing File $SplitArray[8]\n"; push ( @DirArrayOfHashes, { 'Type'=>"File", 'Name'=>"$SplitAr +ray[8]" } ); } } # print "\n"; # for my $LinePtr ( @DirArrayOfHashes ) { # print "Type = $$LinePtr{'Type'} Name = $$LinePtr{'Name'}\n"; # }; # print "\n"; return \@DirArrayOfHashes; }
|
|---|