Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by 2teez (Priest)
on Nov 22, 2012 at 16:12 UTC ( #1005155=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005155]
help
Chatterbox?
Corion idly wonders about creating a series of HTTP requests. There seems to be no framework to generate a series of HTTP requests, like "try all these requests"
[Corion]: This is vaguely inspired by that list of "nasty" strings, which I'd like to replace among HTTP parameters, just to see whether the application crashes, but also for easy downloading of a list of URLs etc
[Corion]: Maybe I'll just conoct something using Algorithm::Permute to create an (OO) generator for such requests, or a simple function.
[Corion]: For testing I imagine one would want to test a random sampling of such "bad"/"unexpected" requests, while for downloading, one would want to generate them all in order, but not necessarily as a huge list

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-01-16 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (151 votes). Check out past polls.