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: Intermediate:
HOw to check in Perl script that directory older then 60 (or other) days old?

 



digioleg54
User

Apr 5, 2017, 9:31 AM

Post #1 of 6 (2972 views)
HOw to check in Perl script that directory older then 60 (or other) days old? Can't Post

I need to check that my directory older then for example 60 days.
For the file I used:
die unless opendir DIR, ".";
foreach my $fname (grep {-f && (5 <= -M)} readdir DIR)
{
do something
}
Can I have something similar to determine directory and remove it with file? (How to rmtree I know)


Laurent_R
Veteran / Moderator

Apr 5, 2017, 11:00 AM

Post #2 of 6 (2971 views)
Re: [digioleg54] HOw to check in Perl script that directory older then 60 (or other) days old? [In reply to] Can't Post

You say 60 days but test your files for an age of 5 days. Can your please explain?

Otherwise, try to replace -f (file) with -d (directory). I haven't tested it, but I guess this should work.


digioleg54
User

Apr 5, 2017, 1:05 PM

Post #3 of 6 (2967 views)
Re: [Laurent_R] HOw to check in Perl script that directory older then 60 (or other) days old? [In reply to] Can't Post

Files 5 days. directories are diferent
But" readdir DIR" means I read files on the directory.


FishMonger
Veteran / Moderator

Apr 5, 2017, 4:54 PM

Post #4 of 6 (2957 views)
Re: [digioleg54] HOw to check in Perl script that directory older then 60 (or other) days old? [In reply to] Can't Post

Is this what you're looking for?

Code
foreach my $dir (grep {-d && (60 <= -M)} readdir DIR)


If not, then you need to provide a better explanation of what you want.


digioleg54
User

Apr 7, 2017, 10:05 AM

Post #5 of 6 (2951 views)
Re: [FishMonger] HOw to check in Perl script that directory older then 60 (or other) days old? [In reply to] Can't Post

But what will be in DIR? files on the directory? I don't need them. I need directories, which are older 60 days. Foreach will not work in this case I think. If I readdir DIR, then I read files on that directory


FishMonger
Veteran / Moderator

Apr 7, 2017, 11:26 AM

Post #6 of 6 (2946 views)
Re: [digioleg54] HOw to check in Perl script that directory older then 60 (or other) days old? [In reply to] Can't Post

Since you're asking that question, it's obvious that you didn't even bother to test it.

Test it and find out the answer.

 
 


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

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