#!/usr/local/bin/perl
#directory.plx

##This will allow the absolute path to be listed instead of relative
use Cwd 'abs_path';

##Get absolute path of input directory
my $top_directory=abs_path($ARGV[0]);

my $count=0;
my $dir_handle=0;



opendirectory($top_directory);
print "$count\n";

#########################
##Define sub-routine

sub opendirectory{

	my $directory=shift(@_);

	opendir ("$dir_handle", '/') or die "Can't find directory $directory: $!\n";

	while ($one=abs_path(readdir("$dir_handle"))){
		next if $one eq "." or $one eq "..";
		print "$one\n";
		
		if (-d $one){
			print "found a directory\n";
			++$count;
			opendir IN, abs_path($one) or die "Can't open directory $_: $!\n";
			while ($two=readdir(IN)){
					$path_two=abs_path($two);
					next if $two eq "." or $two eq "..";
					print "$path_two\n";

					if (-d $two){
				
						print "found a directory\n";
						++$count;
						opendir IN1, abs_path($two) or die "Can't open directory $_: $!\n";
						
						while ($three=readdir(IN1)){
							$path_three=abs_path($three);	
							next if $three eq "." or $three eq "..";
							print "$path_three\n";
											
													
						
							if (-d $three){
								print "found a directory\n";
								++$count;
					
								opendir IN2, abs_path($three) or die "Can't open directory $_: $!\n";
						
								while ($four=readdir(IN2)){
									$path_four=abs_path($four);
									next if $four eq "." or $four eq "..";
									print "$path_four\n";
									}				
							
								
								}				
								closedir IN2;
							
							}	
							closedir IN1 ;
					}
	
				
			}
	
	closedir IN;
	}

}

closedir "$dir_handle";
}

