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


use Cwd 'abs_path';
use Cwd;

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

print "$cur_directory\n";

my $count=0;

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($top_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++;
		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--;
		}			
	}
}

	
