0,0 → 1,102 |
#!/usr/bin/env perl |
# ============================================================================= |
# Create |
# name : Andre Rikkert de Koe date: apr 2011 |
# descr : filefind |
# This is a demo of programming in the perl language. |
# Its part of a project to implement a program to create a directory |
# tree similar to the output of the Unix find program. |
# Because of the example, we don't use the standard File::Find module. |
# EUID : Any user who has read access to all the files being searched for. |
# run : interactive |
# |
# Changes |
# name : date: |
# descr : short description |
# |
# ============================================================================= |
|
use File::Basename; |
use Cwd; |
|
# ============================================================================= |
# Functions |
# ============================================================================= |
|
sub Usage |
{ |
|
my ($progname, $mesg) = @_; |
|
print "Usage : $progname directory\n"; |
print "$mesg\n" |
} |
|
# |
# dir is directory to traverse |
# |
sub traverse |
{ |
my ($dir) = @_; |
|
my $curdir = getcwd(); |
chdir($dir); |
my $curdir2 = getcwd(); |
opendir(FH, $curdir2); |
my @files = readdir(FH); |
foreach $file (@files) |
{ |
my $pfile = $curdir2 . "/" . $file; |
if (-d $file && ! -l $file) |
{ |
if ($file ne ".." && $file ne ".") |
{ |
print "$pfile\n"; |
traverse($file) |
} |
} |
else |
{ |
if (-f $file || -l $file) |
{ |
print "$pfile\n" |
} |
else |
{ |
print("WARNING: Could not process file $pfile\n") |
} |
} |
} |
close(FW); |
chdir($curdir) |
} |
|
sub start_traverse |
{ |
my ($directory) = @_; |
|
print "$directory\n"; |
traverse($directory) |
} |
|
# ============================================================================= |
# MAIN |
# ============================================================================= |
|
$progname = basename($0); |
if ($#ARGV == 0) |
{ |
$directory = $ARGV[0]; |
if (-d $directory) |
{ |
start_traverse($directory); |
} |
else |
{ |
Usage ($progname, "ERROR: No directory $directory found"); |
} |
} |
else |
{ |
Usage ($progname, "ERROR: 1 argument expected"); |
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |