- Timestamp:
- 12/29/07 21:30:36 (13 months ago)
- Location:
- ext/File-Util
- Files:
-
- 2 modified
-
lib/File/Util.pm (modified) (2 diffs)
-
t/03.dirs.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ext/File-Util/lib/File/Util.pm
r17729 r19288 160 160 } 161 161 162 method list_dir (Str $dirname, %options?){ 163 162 method list_dir (Str $dirname, *@options){ 164 163 # my $maxd = $.maxdives; 165 164 my $maxd = 12; … … 197 196 my @shadow = @dirs; 198 197 @dirs = (); 198 my @files = (); 199 my @others = (); 199 200 while @shadow { 200 201 my $f = @shadow.shift; 202 if(@options.grep:{$_ eqv '--no-fsdots'}) { 201 203 next if $f eq '.'; 202 204 next if $f eq '..'; 203 next if $f ~~ /^\./;204 205 my $pathname = $path ~ "/" ~ $f;206 if $pathname ~~ :d {207 @dirs.push($path ~ "/" ~ $f);208 205 } 209 } 210 211 for @dirs -> $dir { 212 self.list_dir($dir); 213 } 206 207 my $fullpath = $path ~ "/" ~ $f; 208 my $pathname; 209 210 if(@options.grep:{$_ eqv '--with-paths'}) { 211 $pathname = $fullpath; 212 } else { 213 $pathname = $f; 214 } 215 216 given $fullpath { 217 when :d { 218 @dirs.push($pathname); 219 } 220 when :f { 221 @files.push($pathname); 222 } 223 default { 224 @others.push($pathname); 225 } 226 }; 227 }; 228 229 my @ret; 230 231 if(@options.grep:{$_ eqv '--files-only'}) { 232 @ret.push(@files); 233 } 234 elsif(@options.grep:{$_ eqv '--dirs-only'}) { 235 @ret.push(@dirs); 236 } 237 else { 238 @ret.push(@dirs, @files, @others); 239 } 240 214 241 # for @options -> $option { 215 242 # } 216 return @ dirs.sort;243 return @ret.sort; 217 244 } 218 245 -
ext/File-Util/t/03.dirs.t
r17728 r19288 8 8 9 9 my $f = File::Util.new; 10 my $d = 'ext/File-Util/t'; 10 11 11 my @files = $f.list_dir('ext/File-Util/t'); 12 my @files = $f.list_dir($d); 13 ok( @files ); 12 14 13 ok( @files ); 15 @files = $f.list_dir($d, '--no-fsdots'); 16 ok( @files.grep:{/^\.\.$/} == 0 ); # only .svn 17 18 @files = $f.list_dir($d, '--dirs-only'); 19 ok( @files.grep:{$_ ~~ :d} == @files && @files > 1 ); 20 21 @files = $f.list_dir($d, '--dirs-only', '--no-fsdots'); 22 ok( @files == 1 && @files.grep:{$_ ~~ :d} == 1 ); # only .svn 23 24 @files = $f.list_dir($d, '--files-only'); 25 ok( @files.grep:{"$d/$_" ~~ :f} == @files ); 26 27 @files = $f.list_dir($d, '--with-paths'); 28 ok( @files.grep:{$_.substr(0, $d.chars) eqv $d} > 0 && 29 @files.grep:{$_.substr(0, $d.chars) !eqv $d} == 0 );
