casimo has asked for the wisdom of the Perl Monks concerning the following question:
what I am trying to do is modify the code to loop through each subdirectory and am having a problem:use Digest::MD5; use File::Find; $|=1; #Autoflush ON! my @list; my %dupes; my @delete; my %digests; my $ctx = Digest::MD5->new; sub check_file { my $file=shift; $ctx->reset; open FILE,$file || die "Cant open $file!\n"; binmode FILE; $ctx->addfile(*FILE); close FILE; my $digest = $ctx->hexdigest; if (exists($digests{$digest})) { print "\t$file is a dupe!\n"; $dupes{$digest}->{$file}=1; push @delete,$file; } else { $digests{$digest}=$file; } } #CHANGE ME!!! my $path='C:\Documents and Settings\user\Desktop\dir\subdir1\2010\01\0 +1'; print "I am going to look for duplicates starting at ".$path."\n"; find({wanted=>sub{if (-f $_) {check_file($_)} else {print "Searching $_\n"}}, no_chdir=>1},$path); print "There are ".@delete." duplicate files to delete.\n"; # Uncomment the below line to lose the duplicates! print "Deleted ".unlink(@delete)." files!"; }
I get the duplicate message but the files are not being added to the @delete array. I feel like I'm missing something with the backslashes but can't seem to figure out the fix.@directories = grep -d,<*>; foreach $directory (@directories) { #CHANGE ME!!! my $path='C:\Documents and Settings\user\Desktop\dir\\' . $directory . + '\2010\01\01'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: delete duplicates in windows subdirectories
by graff (Chancellor) on Jan 02, 2010 at 18:29 UTC | |
by casimo (Sexton) on Jan 02, 2010 at 22:07 UTC | |
|
Re: delete duplicates in windows subdirectories
by Anonymous Monk on Jan 02, 2010 at 18:21 UTC | |
by casimo (Sexton) on Jan 02, 2010 at 21:58 UTC | |
by cdarke (Prior) on Jan 03, 2010 at 17:22 UTC |