Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
I want to find certain files in my system (OS X) and create symbolic links to them. For this, I use File::Find. I want to make sure, not to link to the same file twice. So I dont follow links (follow => 0). But what if I want to rerun the process later and don't want to create all the links already present a second time? Is it sufficient to collect, in a first run, all the devicenumbers and inodes of the existing links in my targetdirectory like this:
my %stat; find ( sub { my($dev,$ino)= stat $File::Find::name; ++$stat{$dev}->{$ino}; }, $targetdirectory);
and then later check like this:
find( { wanted => sub { : : # check whether or not we already know of this file my($dev,$ino)= stat $File::Find::name; return if $stat{$dev}->{$ino}++; : : }, no_chdir => 1, follow => 0, }, '/');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stat to identify files?
by Fletch (Bishop) on Jun 11, 2008 at 12:19 UTC | |
by Skeeve (Parson) on Jun 11, 2008 at 17:13 UTC | |
|
Re: stat to identify files?
by tachyon-II (Chaplain) on Jun 11, 2008 at 13:02 UTC | |
by Skeeve (Parson) on Jun 11, 2008 at 17:12 UTC | |
by alexm (Chaplain) on Jun 11, 2008 at 18:19 UTC | |
by Skeeve (Parson) on Jun 11, 2008 at 19:14 UTC | |
|
Re: stat to identify files?
by Anonymous Monk on Jun 11, 2008 at 10:04 UTC | |
|
Re: stat to identify files?
by scorpio17 (Canon) on Jun 11, 2008 at 21:39 UTC | |
by Skeeve (Parson) on Jun 12, 2008 at 06:06 UTC |