Last active
December 30, 2015 15:18
-
-
Save zhanglintc/6cc6cc3c23273d50fdf5 to your computer and use it in GitHub Desktop.
return a list which contains each file's path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use Cwd; | |
use File::Spec; | |
use File::Basename; | |
sub each_file { | |
my $givenFolder = shift @_; | |
our @pList; # path list to be returned | |
&innerEachFile($givenFolder); | |
return @pList; | |
sub innerEachFile { | |
my $path = shift @_; | |
if(-d $path) { | |
chdir $path or die "can't chdir $path: $!\n"; | |
foreach (<*>) { | |
&innerEachFile(File::Spec->catfile(getcwd, $_)); | |
} | |
chdir (dirname $path) or die "can't chdir ".(dirname $path).": $!\n"; | |
} | |
else { | |
push @pList, $path; # push file path into local @pList | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment