CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
testing file aging with -A

 



garsal
New User

Jul 30, 2008, 8:09 AM

Post #1 of 3 (263 views)
testing file aging with -A Can't Post

I am trying to list files of a certain age. Once I get this working, the selected files need to be deleted. I must be missing something obvious. Below is the source, dir list, and the test output. All help is appreciated. TIA.
#!/usr/bin/perl -w
$argcount=$#ARGV + 1;
$dir2open="";
if ($argcount == 0) {
$dir2open=`pwd`; # no directory parameter, use the one i'm in
print "\n\n\n Using pwd: $dir2open \n\n\n";
}
else {
$dir2open=$ARGV[0];
print "\n\n\n Using pwd: $dir2open \n\n\n";
}

opendir (DIR, $dir2open );

@array=readdir(DIR);

closedir(DIR);
$array = @array; # get the number of elements

foreach my $name (@array){
print $name . " M A Y B E D E L E T E D !!!! \n" if -A $name > 0;

}

print " Total: $array \n";



gary@garylap1:~/perl> l /tmp/gary
total 24
drwxr-xr-x 2 gary users 4096 2008-07-28 15:51 ./
drwxrwxrwt 15 root root 12288 2008-07-30 11:00 ../
-rw-rw-rw- 1 gary users 74 2008-07-28 15:51 file1
-rwxrwxrwx 1 gary users 74 2008-07-28 15:51 file2*



gary@garylap1:~/perl> ./fileage.pl /tmp/gary



Using pwd: /tmp/gary


Use of uninitialized value in numeric gt (>) at ./fileage.pl line 21.
. M A Y B E D E L E T E D !!!!
Use of uninitialized value in numeric gt (>) at ./fileage.pl line 21.
.. M A Y B E D E L E T E D !!!!
Total: 4
gary@garylap1:~/perl> As you can see it did not select the files even with the age test set to zero.Tongue


KevinR
Veteran


Jul 30, 2008, 9:38 AM

Post #2 of 3 (260 views)
Re: [garsal] testing file aging with -A [In reply to] Can't Post

File test operators like -A require you are in the same directory as the file if you use only the name of the file or you have to use the full path to the file.
-------------------------------------------------


garsal
New User

Jul 30, 2008, 9:52 AM

Post #3 of 3 (258 views)
Re: [garsal] testing file aging with -A [In reply to] Can't Post

That made a big difference, it works fine now. Thank you.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives