Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySnooping (Information Retrieval)

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

List Latest File Updates

A few days ago, I needed a list of files that were updated within the last 24 hours.

Generally, I use FTP software to see the date and time of the latest file update. But this project would have taken a long time and would have been a tedious job. There were over a hundred subdirectories to check.

So I made software to do it for me.

And I thought maybe you would have a use for it, too.

The List Latest File Updates software accepts the date and time of the oldest update to list. So if you specify yesterday at the current time, you would get a list of all files updated during the last 24 hours.

The software also accepts the subdirectory to scan for files updated since the specified date and time. Whatever subdirectory is specified, all its subdirectories will also be scanned.

Some uses you might have for the software:

  • Find the log and cache files created by software on your domain.

  • Determine which files were changed after hiring someone to install something for you.

    (If you also need to know which files were deleted, install and initialize Files Monitor beforehand. It reports deletions, additions, and changes.)

  • Determine where you put the file you uploaded a bit ago and it's not where you thought it was.

  • Run every day just to see what files have been updated since the last time it was run.

The List Latest File Updates software is free. Here's the code, no customization required.

<?php
/* 
   List Latest File Updates
   Version 1.0
   March 10, 2014

   Will Bontrager Software LLC
   https://www.willmaster.com/
   Copyright 2014 Will Bontrager Software LLC

   This software is provided "AS IS," without 
   any warranty of any kind, without even any 
   implied warranty such as merchantability 
   or fitness for a particular purpose.
   Will Bontrager Software LLC grants 
   you a royalty free license to use this 
   software provided this notice appears 
   on all copies. 
*/

mb_internal_encoding('UTF-8');
if( ! ini_get('date.timezone') ) { date_default_timezone_set('UTC'); }

$doScan = false;
$cutoff = 0;
$startdate = $dir = '';
if( isset($_POST['startdate']) and strlen($_POST['startdate']) and isset($_POST['dir']) and strlen($_POST['dir']) )
{
   $startdate = $_POST['startdate'];
   $dir = $_POST['dir'];
   $startdate = trim($startdate);
   $dir = preg_replace('!/*$!','',trim($dir));
   $dir = str_replace($_SERVER['DOCUMENT_ROOT'],'',$dir);
   $dir = $_SERVER['DOCUMENT_ROOT'] . $dir;
   if( $startdate and $dir ) { $doScan = true; }
}

function DoScan()
{
   global $startdate,$dir,$cutoff;
   list($date,$time) = preg_split('/\s+/',trim($startdate),2);
   list($year,$month,$day) = preg_split('/\D+/',$date);
   $year = intval($year);
   $month = intval($month);
   $day = intval($day);
   list($hour,$minute,$second) = preg_split('/\D+/',$time);
   $hour = intval($hour);
   $minute = intval($minute);
   $second = intval($second);
   $cutoff = mktime(intval($hour),intval($minute),intval($second),intval($month),intval($day),intval($year));
   GetList("$dir/*");
} # function DoScan()

function GetList($dir)
{
   global $cutoff;
   $files = glob($dir);
   foreach( $files as $file )
   {
      if( is_dir($file) )
      {
         # echo "Scanning Directory: $file\n";
         GetList("$file/*");
      }
      if( is_file($file) )
      {
         $m = 0;
         $c = 0;
         $report = '';
         if( ($m = filemtime($file)) or ($c = filectime($file)) )
         {
            $t = ( $m > $c ) ? $m : $c;
            if( $t >= $cutoff )
            {
               $file = str_replace($_SERVER['DOCUMENT_ROOT'],'',$file);
               echo date('Y-m-d H:i:s',$t) . " $file\n";
            }
         }
      }
   }
} // function GetList()
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>List Latest File Updates</title>
<style type="text/css">
body { margin:0; font-family:sans-serif; font-size:14px; text-align:left; }
th { font-size:.8em; }
p, li, td { font-size:1em; line-height:120%; }
h1 { font-size:1.8em; }
h2 { font-size:1.6em; }
h3 { font-size:1.4em; }
h4 { font-size:1.2em; }
h5 { font-size:1em; }
a { text-decoration:none; color:#1c5292; font-weight:bold; }
a, a img { border:none; outline:none; }
input { width:520px; }
#content { margin:0 0 0 150px; padding:75px 0 100px 50px; width:550px; border-left:6px groove #2F83E5; }
</style>
</head>
<body><div id="content">
<form method="post" enctype="multipart/form-data" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<div style="position:fixed; left:50px; top:50px;">
<a href="//www.willmaster.com/">
<img src="//www.willmaster.com/images/wmlogo_icon.gif" style="width:50px; height:50px; border:none;" alt="Willmaster logo">
</a>
</div>

<h1>List Latest File Updates</h1>

<?php if($doScan): ?>
<h3>Scanning:</h3>
<pre>
Date       Time     File
---------- -------- ------
<?php DoScan(); ?>
</pre>
<div style="height:50px;"></div>
<?php endif; ?>

<h3>Scan Request</h3>
<p>
The date preceding file names is either the date the file was last created/updated or the date the index node was changed.
</p>
<p>
The date has this structure:&nbsp; <span style="font-family:monospace; font-size:larger; white-space:nowrap;">year-month-day hour:minute:second</span>
</p>

<p>
Current system time:&nbsp; 
<span style="font-family:monospace; font-size:larger; white-space:nowrap;"><?php echo( date('Y-m-d H:i:s') ); ?></span>
</p>

<p style="margin-bottom:3px;">
Specify the document directory to look for changed files (use "/" for document root directory).
</p>
<input type="text" name="dir" value="<?php echo(@$_POST['dir']); ?>">

<p style="margin-bottom:3px;">
The software will list all files in the specified directory that were changed on or after the date specified here. (Use the structure above, the format the current system time is reported as.)
</p>
<input type="text" name="startdate" value="<?php echo(@$_POST['startdate']); ?>">

<p>
<input type="submit" value="Scan Now">
</p>

<p style="position:relative; left:-25px; top:45px;">
Copyright 2014 <a href="//www.willmaster.com/">Will Bontrager Software LLC</a>
</p>
</form></div></body></html>

Save the code as a file named ListLatestFileUpdates.php

Upload ListLatestFileUpdates.php to your server in any directory where browsers can load web pages. Make a note of its URL.

To use the List Latest File Updates software:

  1. Put the URL of ListLatestFileUpdates.php into your browser.

  2. Specify the directory to scan (it will also scan the specified directory's subdirectories).

  3. Specify the date and time of the oldest update to list.

  4. Click the button.

The software will list each file in the specified directory and its subdirectories that were added or updated since the specified date and time.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC