Tim Johnson æå:

You can use the -d file test to check if the file is a directory before moving it.

unless(-d $whatever_file){
    do whatever...


-----Original Message----- From: "Shu Hung (æé)" [mailto:[EMAIL PROTECTED] Sent: Fri 6/11/2004 3:50 AM To: Perl Beginner Mail Group Cc: Subject: search and move 'expired files'




        Hello all,
        
        I want a script to move all 'expired files' to a folder.
        So I wrote the script below.
        
        However, a problem came out: the find function run everything
        in the address, including the entire folders structure!!!
        
        





Thanks a lot!!!
One thing: with "-d file test", I found the perldoc of file test.
Here is my final solution.


move_expired_files.pl

#---------------move_expired_files.pl-------------------#
# written by: Koala Yeung
# usage: Inspect the inspected directory.
#        Move all files, last modified before expire time,
#        to the expired directory.

use File::Find;

@inspected_dir = "C:\\";
$expire_time = time - 3600;
$expired_dir = "C:\\temp\\";

find (\&action, @inspected_dir); # inspecting the inspected directory

sub action # identify expired files and move
{
my @file_stat = stat($File::Find::name);
if (($file_stat[9] < $expire_time) && (-f $File::Find::name)) {
$origin_dir = join("\\", split ("/", $File::Find::name));
print "move \"$origin_dir\" \"$expired_dir\" \n";
system ("move \"$origin_dir\" \"$expired_dir\"");
}
}



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to