in reply to Listing Files
When you say compare, what do you mean? Do you want to check for exact identity? Same names? Same size? What?#!/usr/bin/perl use strict; use File::Find; find (\&wanted, '.'); sub wanted { next if -d; # skip if it's a directory # $_ is the name of the file # $File::Find::name is the full path and name to the file print "$File::Find::name\n"; }
Here is a way to put the listings into a hash, so you could cycle thru the hash and compare.
#!/usr/bin/perl -w use strict; use Data::Dumper; sub hashdir { my $dir = shift || '.'; opendir my $dh, $dir or die $!; my $tree = {}->{$dir} = {}; while ( my $file = readdir($dh) ) { next if $file =~ m[^\.{1,2}$]; my $path = $dir . '/' . $file; $tree->{$file} = hashdir($path), next if -d $path; push @{ $tree->{'.'} }, $file; } return $tree; } my $tree = hashdir(shift); print Dumper $tree;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Listing Files
by vchavan (Initiate) on Sep 16, 2011 at 10:44 UTC | |
by aaron_baugher (Curate) on Sep 16, 2011 at 11:50 UTC | |
by dreadpiratepeter (Priest) on Sep 16, 2011 at 11:48 UTC | |
by vchavan (Initiate) on Sep 17, 2011 at 06:23 UTC | |
by aaron_baugher (Curate) on Sep 17, 2011 at 18:12 UTC | |
by zentara (Cardinal) on Sep 16, 2011 at 16:37 UTC |