Jump to content

list files from folder, only one for each date


jasonc

Recommended Posts

I have many files in a folder and wish to only list one of each date

 

these are the file names.

date format (dd/mm/yyy)

 

abc - 12-01-2009 - something.pdf

abc - 12-01-2009 - something else.pdf

abc - 12-01-2009 - another title.pdf

abc - 24-05-2009 - some other text

abc - 24-05-2009 - yet more files

abc - 24-05-2009 - yet another title.pdf

 

if i had these files then i would like the results to be

 

12-01-2009

24-05-2009

 

in an array

 

 

at present i have this script..

 

$files = glob('agendas/*.pdf');
$sortfile = array();
foreach($files as $file){
//Extract date
	if (preg_match('/(\d+)-(\d+)-(\d+)[^.]*?\.pdf/', $file, $reg)) {
	//if (preg_match('/(\d+)-(\d+)-(\d+)-Agenda Item (\d+)[^.]*?\.pdf/', $file, $reg)) {
	//add date to array (file as key)
	$sortfile[$file] = mktime(0,0,0,$reg[2],$reg[1],$reg[3]);
	}
}

 

this only gets the files but i would like to have these files sorted and have only one of each date

 

how would this be done.

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.