http://www.perlmonks.org?node_id=1005155


in reply to Search for a file created today and rename it by appending the current date and copy it to a different location

"..The next step is to rename the file ..."
then check rename function
"..and copy it to a new location."
you can use File::Copy

You may also want to check File::Find, to easily transverse a directory tree.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
  • Comment on Re: Search for a file created today and rename it by appending the current date and copy it to a different location

Replies are listed 'Best First'.
Re^2: Search for a file created today and rename it by appending the current date and copy it to a different location
by karlgoethebier (Abbot) on Nov 23, 2012 at 07:54 UTC
    ...even easier to use: File::Find::Rule.

    «The Crux of the Biscuit is the Apostrophe»

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

    Thanks. Could you please tell me how can i use the File::Find function to search for a file modified or created today?

      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". ;-)