#!/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";
}
#
# dir is directory to traverse
#
sub traverse
{
my ($dir) = @_;
my $curdir = getcwd();
my $curdir2 = getcwd();
foreach $file (@files)
{
my $pfile = $curdir2 . "/" . $file;
if (-d $file && ! -l $file)
{
if ($file ne ".." && $file ne ".")
{
traverse($file)
}
}
else
{
if (-f $file || -l $file)
{
}
else
{
print("WARNING: Could not process file $pfile\n")
}
}
}
}
sub start_traverse
{
my ($directory) = @_;
traverse($directory)
}
# =============================================================================
# MAIN
# =============================================================================
$progname = basename($0);
if ($#ARGV == 0)
{
$directory = $ARGV[0];
if (-d $directory)
{
start_traverse($directory);
}
else
{
Usage ($progname, "ERROR: Not a directory : $directory");
}
}
else
{
Usage ($progname, "ERROR: 1 argument expected");
}