Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Search for a file created today and rename it by appending the current date and copy it to a different location

by perlgb (Initiate)
on Nov 27, 2012 at 04:11 UTC ( #1005788=note: print w/ replies, xml ) Need Help??

Comment on Re^2: Search for a file created today and rename it by appending the current date and copy it to a different location
Re^3: Search for a file created today and rename it by appending the current date and copy it to a different location
by afoken (Parson) on Nov 27, 2012 at 05:11 UTC

    File::Find traverses a directory tree and calls the wanted function for each directory entry found. Inside the wanted function, you can use lstat or stat or one of the -X functions to decide if you want to process that directory entry. Example:

    #!/usr/bin/perl use strict; use warnings; use File::Find; find( { wanted => sub { return unless -l $File::Find::name; print "Found a symlink: $File::Find::name\n"; } }, '.' );

    File::Find comes with a script named find2perl. You invoke it like find, but instead of traversing directories, it writes perl code for performing the directory traversal using File::Find to STDOUT. The generated code is not pretty, may have some unused parts, but it generally works:

    /tmp>find2perl . -type l #! /usr/bin/perl -w eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; #$running_under_some_shell use strict; use File::Find (); # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, '.'); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -l _ && print("$name\n"); }

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005788]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-09-18 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls