How can I get the last file of a directory?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gamemap

How can I get the last file of a directory?

:bust_in_silhouette: Reply From: exuin

When the Directory class reaches the end of the directory it will return an empty string when you call get_next() on it so just look for the empty string and then the name of the previous file is the last file in the folder. Since there’s no method for getting the previous file in the Directory class you’ll have to store the name of the previous file in a variable as well.