Very nifty Brad, One addition though, so she/you can work back from any point: <MoreUntestedCode> $i = 0; $start = strtotime("2006-10-05 12:05am"); while(count($img_array) < 5) { $year = date("Y", strtotime("-$i minutes", $start)); $month= date("m", strtotime("-$i minutes", $start)); $day = date("d", strtotime("-$i minutes", $start)); $hour = date("H", strtotime("-$i minutes", $start)); $hhmm = date("Hi", strtotime("-$i minutes", $start)); $filename = "file.$hhmm.jpg"; if(file_exists("/path/to/$year/$month/$day/$hour/$filename")) { $img_array[] = $filename; } $i++; } print_r($img_array); </MoreUntestedCode> JP -----Original Message----- From: Brad Fuller [mailto:bfuller@xxxxxxxxxxxxxxxx] Sent: Wednesday, November 15, 2006 10:11 AM To: php-general@xxxxxxxxxxxxx Subject: RE: Checking file existence <MoreUntestedCode> $img_array = array(); $i = 0; while(count($img_array) < 5) { $year = date("Y", strtotime("-$i minutes")); $month= date("m", strtotime("-$i minutes")); $day = date("d", strtotime("-$i minutes")); $hour = date("H", strtotime("-$i minutes")); $hhmm = date("Hi", strtotime("-$i minutes")); $filename = "file.$hhmm.jpg"; if(file_exists("/path/to/$year/$month/$day/$hour/$filename")) { $img_array[] = $filename; } $i++; } print_r($img_array); </MoreUntestedCode> > -----Original Message----- > From: Brad Fuller [mailto:bfuller@xxxxxxxxxxxxxxxx] > Sent: Wednesday, November 15, 2006 10:56 AM > To: php-general@xxxxxxxxxxxxx > Subject: RE: Checking file existence > > > <UntestedCode> > > $img_array = array(); > $i = 0; > > while(count($img_array) < 5) { > $hhmm = date("Hi", strtotime("-$i minutes")); > $filename = "file.$hhmm.jpg"; > if(file_exists("/path/to/$filename")) { > $img_array[] = $filename; > } > $i++; > } > > print_r($img_array); > > </UntestedCode> > > > > -----Original Message----- > > From: Ashley M. Kirchner [mailto:ashley@xxxxxxxxxx] > > Sent: Wednesday, November 15, 2006 10:19 AM > > To: PHP General List > > Subject: Checking file existence > > > > > > I have files that are named in the following manner: > > > > file.####.jpg (where #### is an hhmm timestamp [hour and minutes]) > > > > What's the best way to take the current hhmm timestamp and run > > backwards finding the previous 5 files, and checking whether they > > actually exist? There's a possibility one or more might not exist and > > rather than returning a blank value, I want to continue further back > > till I find the next. > > > > So for example, say I have: > > > > file 1122.jpg > > file 1121.jpg > > file 1119.jpg > > file 1117.jpg > > file 1116.jpg > > file 1114.jpg > > > > Notice the gaps, 1120, 1118, and 1115 are missing. But I still want > > to return five, thus 1122, 1121, 1119, 1117, and 1116. > > > > I thought of taking the current timestamp and loop five times, > > subtracting from it every time, but that's assuming all five are there. > > If one's missing then I only have four images. > > > > > > -- > > W | It's not a bug - it's an undocumented feature. > > +-------------------------------------------------------------------- > > Ashley M. Kirchner <mailto:ashley@xxxxxxxxxx> . 303.442.6410 x130 > > IT Director / SysAdmin / Websmith . 800.441.3873 x130 > > Photo Craft Imaging . 3550 Arapahoe Ave. #6 > > http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A. > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php