JJ.
JJ.

Reputation: 9950

How to deal with hidden file extensions

Here's a piece of code:

if (fbFolderBrowser.ShowDialog() == DialogResult.OK)
{
   originalFiles = Directory.GetFiles(fbFolderBrowser.SelectedPath);
   supportedFiles = originalFiles.Where(s => s.EndsWith(".jpg") || s.EndsWith(".bmp") || s.EndsWith(".tiff") || s.EndsWith(".jpeg") || s.EndsWith(".gif")).ToArray();
}

What if in the directory selected, the files' extensions are hidden? Does it mean I won't be able to use "EndsWith?"

What would be the correct way to KNOW the file extensions?

Upvotes: 0

Views: 658

Answers (2)

Abe Miessler
Abe Miessler

Reputation: 85046

You will still see the extension if you access the directory from code. The "hidden" extension only hides it when browsing to files through the UI.

Upvotes: 1

SLaks
SLaks

Reputation: 887365

Hiding file extensions is a behavior of the UI run by the Windows shell.

It has no effect on your code; all actual filepaths will still have extensions.

Bonus: Look at the Path.GetExtension() method.

Upvotes: 4

Related Questions