You could use DirectoryInfo
to get the creation time, order & then just select the first sub-directory. Once you have the directory you can get your files by pattern as you currently are:
string rootPath = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Desktop");
DirectoryInfo directory = new DirectoryInfo(rootPath).GetDirectories()
.OrderByDescending(d => d.CreationTimeUtc)
.First();
FileInfo[] files = directory.GetFiles("*.gif");
You're getting all files in all folders because you're passing SearchOption.AllDirectories
to GetFiles
on the root folder which will return files past the top folder level.