#!/usr/bin/perl -w use strict; use Cwd; # Perl script to traverse a given directory and print when each directory or file is discovered. # This starts from the user's current working directory. my $dir = cwd(); my $discovered = 0; my $processed = 0; chomp (my $current = `pwd`); sub process { $dir = shift; foreach (<$dir/*>) { my $file = $_; $file =~ s/$current\///g; next if (-l $_); if (-f $_) { print "Filename: $file\nDiscovered: $discovered\nProcessed: $processed\n\n"; } if (-d $_) { print "Directory name: $file\nDiscovered: $discovered\nProcessed: $processed\n\n"; process($_); } } } process($dir);