#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
my $path;
if ( $ARGV[0] ){
$path = $ARGV[0];
}
else {
print "Enter path: ";
chomp (my $path = <STDIN> );
}
find( \&wanted, $path );
sub wanted {
print "File: $_\n" if -f;
print "Dir: $_\n" if -d;
}
Output:
steve@ubuntu:~/devel/repos/scripts/file_find$ ./find.pl
Enter path: test
Dir: .
File: b.txt
File: a.txt
Dir: .hidden
Dir: a
Dir: b
Update: Fixed so it allows either a command line arg, and if not present, prompts the user for the path.
Update2: This code actually seems broken since I made the first update, but I don't have time to look at the issue. This is an informational warning only, until I get a chance to look closer. |