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

#ADD packageds to get paths
use Cwd 'abs_path';
use Cwd;

#Get the path of the Top Directory and switch to it
my $Begin_Directory=abs_path($ARGV[0]);
chdir $Begin_Directory;
print "$Begin_Directory\n";

my $cur_directory=getcwd;
#my $top_directory=abs_path($ARGV[0]);
my $file_handle_index=0;
my $depth=0;
my $delimiter="/";

#Initialize count on number of files 
my $count=0;
#Set up Index for file handles: IN_ONE is depth 1 directory, IN_TWO is depth two
#directory, etc.

my @subdirectories;
$subdirectories[0]="/";
my @indexing=("IN_ONE","IN_TWO","IN_THREE","IN_FOUR","IN_FIVE","IN_SIX");

print "$indexing[0]\n";
foreach(@indexing){print "$_\n"}

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

sub opendirectory{

	my $directory=shift(@_);
	print "$directory\n";
	chdir $directory;	
	opendir($indexing[$file_handle_index],$directory) or die "Can't Open Directory $directory: $!\n";
	while ($_=readdir($indexing[$file_handle_index])){
		$full_path=$new_directory.$_;	
		next if $_ eq "." or $_ eq "..";
		$count++;
		#$full_path=abs_path($_);
		print "$full_path\n";

		if (-d $_){
			print "Entering New Directory\n";
			$depth++;
			print "$depth\n";
			$file_handle_index++;
			$subdirectories[$depth]=$subdirectories[($depth-1)].$_.$delimiter;	
			$new_directory=$cur_directory.$subdirectories[$depth];
			print "$new_directory\n";
			opendirectory($new_directory);
			print "Leaving Directory\n";
			pop @subdirectories;
			$depth--;
			$old_directory=$cur_directory.$subdirectories[$depth];
			chdir $old_directory;

			$file_handle_index--;
		}			
	}
}

	
