How about something like this:
#!/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.
In reply to Re: How to read files in a directory, directory path to be given through CMD
by stevieb
in thread How to read files in a directory, directory path to be given through CMD
by ckj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |