#!/usr/bin/perl
#Tree.pm (c)2005-6 ビequency Software
###
#ビequency Software - http://frequencysoftware.com
#Pro ビequency - Proテssional Soフware - http://profrequency.com
#Dream ビequency - Useブl Soフware - http://dreamfrequency.com
###
#Treeing Algorithm - Returns a file & directory tree
#
#This Perl modeule is freeware and may be freely redistributed unchanged.
###
package File::Tree;
$VERSION='1.0.1'; #976547

require Exporter;
our @ISA='Exporter';
our @EXPORT='DisplayTree';

sub DisplayTree {
	my $Path=$_[0]; #Read sent path
	LOOP:

	opendir DIR, $Path or die "Did not open $Path.  ($!.)\n";
	readdir DIR; readdir DIR; #. + ..
	while ($_=readdir DIR) {
	if (-d "$Path\\$_") { #Unique dirs
		$Dirs{"$Path\\$_"}=1;
		push @Tree, "$Path\\$_";
	}
	else { push @Tree, "$Path\\$_"; }
	}
	closedir DIR;
	foreach $Dir (keys %Dirs) {
		$Path=$Dir;
		undef $Dirs{$Dir};
		foreach (keys %Dirs) { #Reform hash
			if ($Dirs{$_}==1) { $DirsSorted{$_}=1; } #Remove visited Dirs
		}
		%Dirs=%DirsSorted;
		undef %DirsSorted;
		goto LOOP;
	}

	@Tree=sort @Tree;
	return @Tree;

}

1;

__END__

=head1 NAME

File::Tree - Treeing Algorithm

=head1 SYNOPSIS

  use File::Tree;

  my @Tree=File::Tree->DisplayTree(<Directory/>);

  @Tree=Tree('.');
  foreach (@Tree) { print "$_\n"; }

=head1 DESCRIPTION

This module trees all the files and directories in a directory and
returns an array of the fully paved filenames.

Example uses:

* To delete all the files in a directory for removal,

* To count files,

* To count directory depth.

=head1 UPDATED

Version 1.0.1 (976547): Release.

=head1 VERSION

v1.0.1 (976547)

=head1 COPYRIGHT

Code is copyright (c)2005-6 Pro Frequency.

=head1 AUTHOR INFORMATION

File::Tree was created by Pro Frequency, a division of Frequency
Software.  
Pro Frequency, Professional Software - http://profrequency.com - 
Dream Frequency, Useful Software - http://dreamfrequency.com - 
Frequency Software, Corporate Information - http://frequencysoftware.com.  
Free technical support: http://profrequency.com/support.  
This Perl module is free software and may be freely redistributed
unchanged.

=cut
