Hi Ashley, Are all the files called file.xxxx.jpg or could they have other names such as clouds.1123.jpg, field.2034.jpg etc? If they all have the same name, you could use something like scandir() and then just use the first 5 items in the returned array. You could also loop through the directory with readdir() and add the filenames to an array. You could index this array with the 4 digit string, ksort it and then use the first/last 5 entries. This would work even if the files had different names. The downside of these suggestions is that if there are lots of files you would end up with a large array stored in memory. Alternatively, you could get the OS to do the work through an exec call to something like 'ls *.????.jpg' or similar. The downside of this however is that it is then OS dependent. Hope this gives you some ideas though. Edward > -----Original Message----- > From: Ashley M. Kirchner [mailto:ashley@xxxxxxxxxx] > Sent: 15 November 2006 15:19 > 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