paurus has asked for the wisdom of the Perl Monks concerning the following question:
$file is only the basename. When I use the full path returned by File::Find, it doesn't meet my hash requirements, because each path is different (as I am sure you aready know..)#!/usr/bin/perl -w # use pragmas ##### # use diagnostics; use strict; # use modules ##### use File::Find; use File::Basename; # Declare variables; ##### my $file; my %count; my @total_files; # Make sure command line argument is supplied ##### die "No command line arguments: $!\n" unless @ARGV; # wanted subroutine for File::Find ##### sub wanted { $file = $File::Find::name; if (basename($file) =~ /^\.$|^\.\.$|^\.DS/) { next; } # .DS_ f +or Mac OS parse push(@total_files, $file = basename($file)); } # process @ARGV ##### find(\&wanted, @ARGV); # create hash for basename file seen count ##### foreach $file(@total_files) { $count{$file} += 1; } # print to STDOUT any file not seen 2 or more times ##### foreach $file (keys %count) { if($count{$file} < 2) { print "SYNC this file: $file \n";
I am not sure how to identify by path each file that needs to go from the directory in which it exists to the directory in which it does not exist. Could you please steer me in a direction which would cause the code to "smartly" identify and sync each file which does not already exist in each location simultaneously?} } # for STDOUT format cleanliness ##### print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: files sync
by BUU (Prior) on Aug 06, 2005 at 22:46 UTC | |
by DrAxeman (Scribe) on Aug 07, 2005 at 04:16 UTC | |
|
Re: files sync
by itub (Priest) on Aug 07, 2005 at 02:07 UTC | |
|
Re: files sync
by kral (Monk) on Aug 08, 2005 at 07:16 UTC |