Last active
December 18, 2015 14:09
-
-
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.
This file contains hidden or 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 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