#!/usr/bin/perl use warnings; use strict; if ( not defined $ARGV[0] ) { print "No search directory given.\n"; exit; } else { checkNames($ARGV[0]); } # exit; sub checkNames { use warnings; use strict; my $thisdir = shift; my $thisfile; if ( $thisdir =~ /[^0-9A-Za-z\-\.\/]/ ) { print "Directory $thisdir contains strange characters.\n"; } opendir(THISDIR, $thisdir) or die "Couldn't read from $thisdir.\n"; NAMES: while ( $thisfile = readdir(THISDIR) ) { if ( -d $thisfile ) { # Skip the . and .. directories. if ( $thisfile =~ /^\.{1,2}$/ ) { next NAMES; } print "Recursing into $thisdir/$thisfile.\n"; checkNames("$thisdir/$thisfile"); } if ( -f $thisfile ) { if ( $thisfile =~ /[^0-9A-Za-z\-\.]/ ) { print "File $thisdir/$thisfile contains strange characters.\n"; next NAMES; } } if ( not -d $thisfile and not -f $thisfile ) { # If it isn't a file and it isn't a directory, ignore it. next NAMES; } } closedir(THISDIR); }