Skip to content

Instantly share code, notes, and snippets.

@zhanglintc
Last active December 30, 2015 15:18
Show Gist options
  • Save zhanglintc/6cc6cc3c23273d50fdf5 to your computer and use it in GitHub Desktop.
Save zhanglintc/6cc6cc3c23273d50fdf5 to your computer and use it in GitHub Desktop.
return a list which contains each file's path
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