Find Highest File Name

  • Thread starter Thread starter markcash
  • Start date Start date
M

markcash

I have a web application where I am displaying the current inmate
population for the county jail. Part of the information that I
display is the mugshot. Unfortunately, they have changed the way the
mugshots are being named. So I need to read a directory and get the
newest image. The problem is that I can use the Create or Modified
Date.

Here is an example of what I have:
4580.001.jpg
4580.002.jpg
4580.003.jpg
etc.
etc.

The "4580" corresponds to the inmate and the ".001" is just a
sequential number for multiple mugshots of the same inmate. The ".
003" tells me that this is the latest image. Without knowing what
this number may be, is there an easy way to always retrieve the newest
image?

Any help that you can offer will be greatly appreciated. They are on
my back to get this back online and this is the only issue left for me
to resolve.

Mark
 
Based on what you have written, the count of files that matches the pattern
InmateNumber.*.jpg, should be the same as the highest value. If there are
gaps in the sequence however, this won't be true.
 
Family said:
Based on what you have written, the count of files that matches the pattern
InmateNumber.*.jpg, should be the same as the highest value. If there are
gaps in the sequence however, this won't be true.

If there are gaps in the sequence, presumably you could just iterate
through every file matching the pattern "4580.*.jpg", and keep a record
of the highest value:

Something along these lines:
Psuedo-code:

dim iHighest, iCurrent as integer
For Each filename matching InmateNumber & ".*.jpg"
'Get the photo ordinal
iCurrent = Integer.Parse(filename.split(".")(1))
if iHighest < iCurrent then
iHighest=iCurrent
End if
Next

dim sNewestFile as string = InmateNumber & "." & iHighest & ".jpg"
 
I have a web application where I am displaying the current inmate
population for the county jail. Part of the information that I
display is the mugshot. Unfortunately, they have changed the way the
mugshots are being named. So I need to read a directory and get the
newest image. The problem is that I can use the Create or Modified
Date.

Here is an example of what I have:
4580.001.jpg
4580.002.jpg
4580.003.jpg
etc.
etc.

The "4580" corresponds to the inmate and the ".001" is just a
sequential number for multiple mugshots of the same inmate. The ".
003" tells me that this is the latest image. Without knowing what
this number may be, is there an easy way to always retrieve the newest
image?

Any help that you can offer will be greatly appreciated. They are on
my back to get this back online and this is the only issue left for me
to resolve.

Mark

If you just add the list of filenames to an array (which
Directory.GetFiles returns) you can just call the default Array.Sort()
on the array to put the filenames in order. Then you just need to
return the upper boundary of the array.

Here's a complete console project that demonstrates:

/////////////////////
Imports System.IO

Module Module1

Sub Main()
Dim mugshots As String() = Directory.GetFiles("C:\Mugshots",
"4580.*.jpg")

Array.Sort(mugshots)

Console.WriteLine(mugshots(mugshots.Length - 1))

Console.Read()
End Sub

End Module
/////////////////////

Thanks,

Seth Rowe
 
If you just add the list of filenames to an array (which
Directory.GetFiles returns) you can just call the default Array.Sort()
on the array to put the filenames in order. Then you just need to
return the upper boundary of the array.

Here's a complete console project that demonstrates:

/////////////////////
Imports System.IO

Module Module1

Sub Main()
Dim mugshots As String() = Directory.GetFiles("C:\Mugshots",
"4580.*.jpg")

Array.Sort(mugshots)

Console.WriteLine(mugshots(mugshots.Length - 1))

Console.Read()
End Sub

End Module
/////////////////////

Thanks,

Seth Rowe- Hide quoted text -

- Show quoted text -

Yea, I don't know for sure if there may be gaps in the numbers or not,
so a method other than count would probably be best.

Thanks for everyones input, I will try this out!!

Mark
 
Filter by the first number and cycle through checking creation date and
time.

Sorry for the short response (no code) but I am typing one handed beacuse I
have a sick cat in laying in the other arm :)
 
Back
Top