[Chicago-talk] chown inside a script
Brian Katzung
briank at kappacs.com
Thu Dec 6 19:56:52 PST 2007
Jay Strauss wrote:
> On Dec 6, 2007 6:41 PM, Brian Katzung <briank at kappacs.com> wrote:
>> Jay,
>>
>> Here's a rough code snippet to get you started.
>>
>> use File::Find;
>>
>> # Queue looks like /some/path/closed/user_name/file_name
>> my $base_dir = '/some/path/closed';
>>
>> sub proc_files
>> {
>> return unless (-f $File::Find::name &&
>> $File::Find::name =~ m{^\Q$base_dir\E/([^/]+)/([^/]+)$});
>>
>> my ($user, $file) = ($1, $2);
>> print "Process file $file in queue for user $user\n";
>> }
>>
>> find({ 'wanted' => \&proc_files, 'follow' => 0, 'no_chdir' => 1 },
>> $basedir);
>>
>> - Brian
>
> Thanks Brian, I'm not exactly sure what the regex does.
It makes sure the current path being examined is the base_dir plus two
components, remembering those two components (think of it as a path
check, split, and splice all in one).
> I don't know
> wher \Q and \E do, the other part I think is match and remember the
> directory and filename.
I'm going to make you do *some* work. :-) See man/perldoc perlre.
> Also, I already know where the files are, what's the advantage of
> using File::Find?
And it's a good thing you know, too, because File::Find doesn't "find"
files! It's a directory tree iterator, which is exactly what I wanted
here (with the "filtering" as indicated)--to iterate over each "queued"
file.
> Jay
- Brian
--
Brian Katzung, Kappa Computer Solutions, LLC
Leveraging UNIX, GNU/Linux, open source, and custom
software solutions for business and beyond
Phone: 877.367.8837 x1 http://www.kappacs.com
More information about the Chicago-talk
mailing list