Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get file with highest number in filename 1

Status
Not open for further replies.

simmerdown

Programmer
Jun 6, 2000
100
US
I've got a webcam that's archiving photos to a directory on our server: a new photo every 5 minutes, and a unique file name for each photo. I could just have the camera overwrite the existing image file, and point an html page to the constantly-updating image, but then that wouldn't be archiving, would it? Thus I'm back to the images being given unique and regularly incremented numeric file names.

The point/ the question:
Is there a way to have CF determine
1) [COLOR=003366]which file in the directory has the highest-numbered file name?[/color]
or
2) [COLOR=003366]which file has the newest "Last Modified" date?[/color]
or
3) [COLOR=003366][insert better solution here]?[/color]

I'd then need to generate a link to that file.

It's probably something simple, obvious, and common, but I'm stuck. Thanks for any help/suggestions at all.
 
If you use CFDIRECTORY to get a list of the files that are in the directory and sort these by the filename, then if you just get the first record that is returned from that query, that will be the largest numbered file

something like this:

<CFDIRECTORY directory=&quot;thisdir&quot; name=&quot;getFiles&quot; SORT=&quot;Name ASC&quot;>

<CFSET lastfileval = #getFiles.Name#>

Something like this should work, I will have a think about another way of doing it if this doesn't work.
 
You were right on, [COLOR=003366]arperry[/color]. I just changed it a bit to:

[COLOR=003366]<cfdirectory directory=&quot;pathtoimages&quot; name=&quot;getFiles&quot; sort=&quot;Name DESC&quot;>

<cfoutput query=&quot;getFiles&quot; MaxRows=&quot;1&quot;>
<img src=&quot;relativepath/#Name#&quot; /><br />
</cfoutput>[/color]

Works quite spiffily. Thank you thank you!
 
You could also look into the CreateUUID() ColdFusion Function to create unique names.

:) - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top