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

Re^3: remove directory in perl

by thunders (Priest)
on May 20, 2009 at 15:50 UTC ( #765263=note: print w/ replies, xml ) Need Help??


in reply to Re^2: remove directory in perl
in thread remove directory in perl

See stat for some information on how to get Modify Time of a directory. It returns an array with various data on a supplied file or directory.

#last modify time of /usr/bin: print scalar localtime((stat("/usr/bin"))[9]); # Thu May 14 13:52:17 2009 my $SECONDS_IN_DAY = 60*60*24; $days_old = (time-(stat($dirname))[9]) / $SECONDS_IN_DAY; if($days_old > 5){ #do_something }


Comment on Re^3: remove directory in perl
Download Code
Replies are listed 'Best First'.
Re^4: remove directory in perl
by ikegami (Pope) on May 20, 2009 at 15:55 UTC

    -M is simpler.

    The OP already asked this question here and here

Re^4: remove directory in perl
by ikegami (Pope) on May 20, 2009 at 15:56 UTC

    -M is simpler.

    The OP already asked this question here and here

      That's true, for the specific case I gave -M is simpler. The only thing to note is that -M doesn't use time(). It uses script start time. So in a long running process it may not be what you want:

      $ perl -e ' print -M "/usr/bin","\n"; sleep(120); print -M "/usr/bin", +"\n"' 5.9218287037037 5.9218287037037

      Thanks, I didn't realize I was responding to a question that has already been thoroughly answered.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://765263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2015-08-01 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls