All Scripts backed by 10 years in business, free support, free updates and a 30 day money back guarantee.
Download Purchase Programming F.A.Q. Support Contact
Commercial Perl Scripts
All Form Pro Updated
Count It
Form Mailer + Attachments
Client File Manager
Da Godfaddah
Dropbox Updated
FAQ Builder
HT Manager Updated
RegisterHT
Mailing List Server
Page Updater - Text
Page Updater Pro Updated
PS Guestbook Updated
PS Lightning Search Updated
Quick File Mailer
Quick MySQL
Select-A-File
Upload Center
Free Perl Scripts
Access Log Viewer
All Form
Epoch Converter
Error Log Viewer
Invoice Center
PS Upload
Question Manager
Quick CHMOD
QuickHT
Site File Finder
Site File Lister
SSI Tag Maker
Perl Modules
Monger Calendar
Monger File
Monger Mail
Monger Persist
JavaScript Generators
PopUp Windows
Meta Gen
RGB / Hex Converter
Page Colors
Sudoku
Tutorials and FAQs
Cookies
Using CuteFTP
Using WS_FTP
Installing Scripts
Debugging
Utilities
env_vars.pl
backup.pl
restore.pl
check_email.pl
date.pl
dayname.pl
fileage.pl
format_length.pl
format_url.pl
getfile.pl
parse.pl
redirect_html.pl
Free Services
Epoch Converter
TLD Registries
RGB/Hex FInder
Colour Checker
ASCII Codes
Policies
Terms and Conditions
Privacy Policy
Refund Policy
Site Map

Form Processor with no SPAM from robots.

Anti-spam, anti-robot, anti-flame, Guestbook for your website.

Manage Remote websites from your website. Allow clients to update sections of their own web pages.

Secure file manager with upload progress meter. A printer's best friend. Find out more.

Utility Name: fileage.pl
Platform: UNIX or Linux
Requires: Perl4 or higher


There are a number of different ways you can determine how old a file is or when it was last modified. However, trying to find these examples can be difficult at best and if you don't use them all the time, you quickly forget how to do it and have to relearn it each time.

This utility will give you the age of a specified file in seconds, minutes, hours, days, weeks, years. It will also return the date the file was created (placed on the server) and the date it was last modified. The first six values are returned in decimal format but you can also retrieve them in integer format (no decimals, rounded to the lowest whole value).

For our example, we will use two files. The file "old.txt" was placed on the server one year, three days, four hours and twelve minutes ago. The second file "new.txt" was placed on the server precisely 36 hrs ago. First I will show you what age values the program returns based on the above examples.

  Old File New File
Use Integer Yes No Yes No
Seconds 31810320 31810320 129600 129600
Minutes 530172 530172 2160 2160
Hours 8836 8836.2 36 36
Days 368 368.175 1 1.5
Weeks 52 52.596428 0 0.2142857
Years 1 1.008698 0 0.0041095
Created Wednesday, September 21, 22:12:46, 1998 Monday, September 24, 12:45:13, 1999
Last
Modified
Saturday, June 19, 08:12:12, 1999 Monday, September 24, 12:57:13, 1999


To call the script you must pass it two parameters. The first is the format that you want the age returned in and the second is the absolute path to the file you are querying.

Formats
The fileage() subroutine accepts nine (9) different formats. These formats are:
  • sec - This returns the age of the file in seconds.
  • min - This returns the age of the file in minutes.
  • hr - This returns the age of the file in hours.
  • day - This returns the age of the file in days.
  • wk - This returns the age of the file in weeks.
  • yr - This returns the age of the file in years.
  • date - This returns the date the file was created.
  • mod - This returns the date the file was last modified.
  • '' or 0 - Passing a null value as the format parameter will return a list containing all of the above values in the following order:

($seconds, $minutes, $hours, $days, $weeks, $years, $date_created, $date_modified) = filedate('', $foo);

To use this utility, load it with your other script that is calling it and CHMOD it to 755. The other script must have a require statement before the subroutine fileage() is called. The require statement looks like this:

require 'fileage.pl';

The first parameter you pass is the format and the second parameter you pass is the absolute path to the file being tested. If you want to use the integer function so that you are not getting any decimals, then add a third parameter of '1'.

Here are some example calls:

  • $age_in_seconds = fileage('sec', '/home/name/html/path/to/file.txt');

  • $age_in_minutes = fileage('min', $filepath, 1);

  • $age_in_hours = fileage('hr', "$Data/$user/$file");

  • $age_in_days = fileage('day', "$FILE{$id_num}.txt", 1);

  • $age_in_weeks = fileage('wk', $file_array[$b], 1);

  • $age_in_years = fileage('yr', "$Root/$Dir/$File");

  • $date_created = fileage('date', "$Data/$file");

  • $date_modified = fileage('mod', $FilePath);

  • @age_array = fileage('', $FilePath);

  • @age_array = fileage(0, "$Data/$file");

  • @age_array = fileage(0, "$Data/$file", 1);

If you have any difficulty using this script of it's not explained clear enough, please email me and tell me exactly where you having the problem and I will try to explain it better in this document.

  ©2009 All rights reserved, PerlServices.net. Website hosting by LinuxHostingPlans.com