Created
March 26, 2016 23:18
-
-
Save afnanenayet/7bad2a6eb3ce1745532d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use Cwd; # module for finding the current working directory | |
$|=1; # turn off I/O buffering | |
$num_arguments = $#ARGV + 1; | |
$directory_name = $ARGV[0]; | |
foreach $arg_index (0 .. $num_arguments) { | |
if ($ARGV[$arg_index] eq "-name") { | |
$file_name = $ARGV[$arg_index + 1] or die "File name not provided\n"; | |
} | |
} | |
opendir(DIR,$directory_name) or die "Can't open the current directory: $!\n"; | |
# read file/directory names in that directory into @names | |
@names = readdir(DIR) or die "Unable to read current dir:$!\n"; | |
closedir(DIR); | |
foreach $name (@names) { | |
next if ($name eq "."); # skip the current directory entry | |
next if ($name eq ".."); # skip the parent directory entry | |
if ($name eq $file_name){ # is this a directory? | |
print "$name\n"; | |
next; # can skip to the next name in the for loop | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment