satyakm has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone, I have around 2000 files in a directory. During processing of these files, a temp* will be created for each file and its removed after processing that file. If the processing is unsuccessful, temp* file still exists. Can u plz help me to write a script to automate this process using Perl ie., when a temp* file is found (which stays for abt 10 secs max), I hv to move that temp* file to some other folder. Thanks in advance, Satish
  • Comment on Processing files in a directory recursively

Replies are listed 'Best First'.
Re: Processing files in a directory recursively
by ikegami (Patriarch) on Nov 10, 2008 at 10:55 UTC

    You could use File::Find::Rule to find the files

    use File::Find::Rule qw( ); # Only delete files created more than 60 seconds ago. my $old = time() + 60; my @to_move = File::Find::Rule ->file() ->name( 'temp*' ) ->ctime( ">=$old" ) ->in( $dir );

    (Untested)

    Then use move in File::Move

Re: Processing files in a directory recursively
by marto (Cardinal) on Nov 10, 2008 at 10:51 UTC