Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to know how to identify a last image file in a folder, i want to loop all the image files in a folder from starting to last and i need to place those images in image box
Posted

Interesting question. What defines the last file? Is it that it was the last file added? Is it the last file by name? What about if the order is reversed?

Anyway, you don't actually need to worry about this. You can let the .NET framework take care of it for you using the Directory class. Here's how you would do it:
string[] files = Directory.GetFiles(@"c:\myimages", "*.jpg");


-----------------

From JSOP: The last file in the folder is the last one in the list when you do a GetFiles call. Files are stored in a "natural" order (the order the were placed/copied to the disk). The last one placed on the disk will NOT necessarily have the newest modification date, either. You can thank the guys that invented DOS for this little gem. :)


 
Share this answer
 
v5
What's the problem with this?
C#
string[] files = Directory.GetFiles(path);
count = files.length;


-----------------
From JSOP: I think he just wanted to know when he got to the last file. He can do that by using the method cited by Pete, and the iterate through the returned string array until he reaches the last item.


 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900