Skip to content

Instantly share code, notes, and snippets.

@akirad
Last active December 18, 2015 14:09
Show Gist options
  • Save akirad/5794860 to your computer and use it in GitHub Desktop.
Save akirad/5794860 to your computer and use it in GitHub Desktop.
A perl script which can show files and dirs under a dir. It can also show dot files. It should work when a path of a dir is long.
use strict;
use warnings;
my $dir = $ARGV[0];
if(! -d $dir){
die "Invalid argument.";
}
$dir =~ s|\\|/|g; # Just in case, change '\' to '/' in the Windows path.
getFileList($dir);
sub getFileList{
my $dir = shift;
print("$dir\n");
opendir(my $dh, $dir);
my @fileList = readdir($dh);
closedir($dh);
foreach my $file (sort @fileList){
if($file =~ /^\.{1,2}$/){
next;
}
if( -d "$dir/$file"){
getFileList("$dir/$file");
}
else{
print("$dir/$file\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment