checking file age

S

Stu

Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks the
last access time of a file.

For example, if I pass the following:

c:/temp/testfile 5 GT

The function will check the last access time of the file c:/temp/
testfile and see if it is greater than 5 minutes old.

If I pass c:/temp/testfile 6 LE

The function will check the last access time of the file c:/temp/
testfile and see if it is less than or equal to 6 minutes old.

If the anwer is yes I want to return 1 for TRUE else return 0 for
false.

Thanks in advance for all that answer this post






I
 
P

Paul Lalli

Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks
the last access time of a file.

For example, if I pass the following:

c:/temp/testfile    5     GT

The function will check the last access time of the file c:/temp/
testfile and see if it is greater than 5 minutes old.

If I pass c:/temp/testfile    6     LE

The function will check the last access time of the file c:/temp/
testfile and see if it is less than or equal to 6 minutes old.

If the anwer is yes I want to return 1 for TRUE else return 0 for
false.

Thanks in advance for all that answer this post

What have you done so far? What part is causing you problems? Please
post a short but complete script that demonstrates the issue you're
having.

To find the last access time of a file in seconds, you use the -A
operator:
my $secs = -A $file;

To find minutes from seconds, you divide by 60
my $minutes = $secs / 60;

To compare a number to a given value, you use one of the numeric
comparison operators: <, >, <=, >=, ==, !=

To learn how to write a subroutine, you read `perldoc perlsub` by
typing those two words in a command window.


If you make an attempt to solve your own problem, people here will be
very willing to help you and show you where you might be going wrong.

Paul Lalli
 
S

Scott.Jo

Stu 写é“:
Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks the
last access time of a file.

For example, if I pass the following:

c:/temp/testfile 5 GT

The function will check the last access time of the file c:/temp/
testfile and see if it is greater than 5 minutes old.

If I pass c:/temp/testfile 6 LE

The function will check the last access time of the file c:/temp/
testfile and see if it is less than or equal to 6 minutes old.

If the anwer is yes I want to return 1 for TRUE else return 0 for
false.

Thanks in advance for all that answer this post






I
It's your homework?
 
S

Stu

Stu $B<LF;(B:












It's your homework?- Hide quoted text -

- Show quoted text -

No it is not, just needed help with the -A for access time. All done
thanks eveyr
 
J

Jürgen Exner

Stu said:
Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks the
last access time of a file.

See
perldoc -f -X (you are looking for -A)
perldoc perlop (you are looking for > and <=)

jue
 
S

Stu

What have you done so far?  What part is causing you problems?  Please
post a short but complete script that demonstrates the issue you're
having.

To find the last access time of a file in seconds, you use the -A
operator:
my $secs = -A $file;

To find minutes from seconds, you divide by 60
my $minutes = $secs / 60;

To compare a number to a given value, you use one of the numeric
comparison operators: <, >, <=, >=, ==, !=

To learn how to write a subroutine, you read `perldoc perlsub` by
typing those two words in a command window.

If you make an attempt to solve your own problem, people here will be
very willing to help you and show you where you might be going wrong.

Paul Lalli- Hide quoted text -

- Show quoted text -

Paul,

Thanks for your help but I think -A returns the value in days and not
seconds. (see below).

I am going to take the current time in secs and subtract the stat time
and that should do it for me.


File test Meaning
-r File is readable by effective uid/gid
-w File is writable by effective uid/gid.
-x File is executable by effective uid/gid.
-o File is owned by effective uid.
-R File is readable by real uid/gid.
-W File is writable by real uid/gid.
-X File is executable by real uid/gid.
-O File is owned by real uid.
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
-t Filehandle is opened to a tty
-u File has setuid bit set.
-g File has setgid bit set.
-k File has sticky bit set.
-T File is an ASCII text file (heuristic guess).
-B File is a "binary" file (opposite of -T).
-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time (Unix, may differ for other platforms)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,208
Messages
2,571,084
Members
47,683
Latest member
AustinFairchild

Latest Threads

Top