Greatest FileName in folder

talahaski

Active member
Joined
Apr 29, 2004
Messages
35
I have a file folder that has files named with numbers such as 1.jpg. 2.gif 3.jpg 4.jpg

I need a method to get the greatest numbered file so I can continue adding additional files having the next number.

Is there any easy way to get the largest number file without having to loop through each file and check the names. Perhaps some way to sort by name and grab the greatest number and return that number?
 
You cant find the highest number in any kind of group if you dont look at all of the elements.
All sorting will eventually look at all of the elements.

But anyway, use the System.IO.Directory.GetFiles() to get all of the files (and no, GetFiles doesnt count as looking at each file.
You can put it in an array, then loop through the array, converting their filenames without extension into integers, and then sort the array. :)
 
how did you implement it?

talahaski said:
thanks, that is what I ended up doing, was just hoping there might be a easy way to do this.

i view your answer but can you tell me how did you implement it with code(show me the code)

and i have another question that when i post a message how can i see the reply?
can you post me the answer to the email wissam_r_b@hotmail.com
thank you for the help and for the time
 
And why cant you do it yourself?
Sending answers via email defeats the purpose of a forum.
You can put it in an array, then loop through the array, converting their filenames without extension into integers, and then sort the array.
Put it into an array:
XYZ = System.Directory.GetFiles(...)
loop through the array, converting their filenames without extension into integers
For LV = 0 To XYZ.GetUpperBound
You need another array for an array of integers.
Sort the array:
Array.Sort(IntXYZ)
:).
 
Back
Top