Jump to content

[SOLVED] search a folder for highest number file name


jasonc

Recommended Posts

i have a folder with many files in it all numbered with dates.

 

i.e. 20090701

which would be (1 July 2009)

 

each file is a HTML file

 

20090701.html

 

and i wish to find the most up-to-date file in this folder.

 

i have this so far but thought i'd try to use a mask but this did not work

Code:

 

<?

$maxfile = max(scandir($uploaddir . "articles/*.htm"));

echo("'" . $maxfile . "'");

?>

 

reason being is that their are some other files also in this folder but i only want to have the files with .htm as the ext and not all the other files to be used in the list.

 

how do i stop the other files from being in this list ?

 

 

 

 

EDITED....

 

 

 

$maxfile = max(glob("articles/*.htm"));

echo("'" . $maxfile . "'<br><br>");

 

 

preg_match('{(\d+-\d+-\d+)}', $maxfile, $m);  IS THIS THE CORRECT WAY TO GRAB THE NUMVERS WITH THE - BETWEEN THEM ?

 

 

echo $m[1];

I would use pathinfo

<?php
$files = glob($uploaddir . 'articles/*.htm');
$maxfile = $files[count($files) - 1];
echo $maxfile . '<br>';
$dt = pathinfo[$maxfile,PATHINFO_FILENAME];
echo date('Y-m-d',strtotime($dt));
?>

 

Ken

I would use pathinfo

<?php
$files = glob($uploaddir . 'articles/*.htm');
$maxfile = $files[count($files) - 1];
echo $maxfile . '<br>';
$dt = pathinfo[$maxfile,PATHINFO_FILENAME];
echo date('Y-m-d',strtotime($dt));
?>

 

Ken

 

i get the following error...

 

Parse error: syntax error, unexpected '['  in the $dt = pathinfo[$maxfile,PATHINFO_FILENAME];  line

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.