When you open a picture in Windows Photo Viewer, you can navigate backward and forward between supported files using arrow keys (next photo / previous photo).
The question is: how to get path of the next file given path of the current file in the folder?
You can do this easily by getting all paths into a collection and keep a counter.If you don't want to load all file paths into memory you can use
Directory.EnumerateFiles
andSkip
method to get next or prev file.For example:Ofcourse you need some additional checks, for example in
NextFile
you need to check if you get to the last file, you need to reset the counter, likewise in thePreviousFile
you need to make sure counter is not0
, if so return the first file etc.