I am just a newbie to VS, C# and XAML.
I have this project am building which I want to display all images in my D;\
drive. So I actually got this code from this question and luckily for me I had it working without any difficulty. I can tell the code is working because my app now takes about 2 minutes to start up, so its been delayed due to the searched images
public static IEnumerable<string> GetDirectoryFiles(string rootPath, string patternMatch, SearchOption searchOption)
{
var foundFiles = Enumerable.Empty<string>();
if (searchOption == SearchOption.AllDirectories)
{
try
{
IEnumerable<string> subDirs = Directory.EnumerateDirectories(rootPath);
foreach (string dir in subDirs)
{
foundFiles = foundFiles.Concat(GetDirectoryFiles(dir, patternMatch, searchOption));
}
}
catch (UnauthorizedAccessException) { }
catch (PathTooLongException) { }
}
try
{
foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch));
}
catch (UnauthorizedAccessException) { }
return foundFiles;
}
I use this line of code to call the function GetDirectoryFiles
string[] filePaths = {};
string[] extObj = { "*.JPG", ".JPEG", ".PNG", ".GIF", ".BMP*.jpg", ".jpeg", ".png", ".gif", ".bmp" };
foreach(var ext in extObj)
filePaths.Concat(GetDirectoryFiles(@"D:\", ext, SearchOption.AllDirectories));
System.Diagnostics.Debug.WriteLine(filePaths.Length);
But am having an issue... When the filePaths.Length
is outputted I get 0
. I don't actually know why but I know I have at least 4000 .jpg
images in my D:\
drive, so I shouldn't be getting 0.
My question in a nutshell: I want to load all images in my D:\
drive excluding the paths which returns an UnauthorizedAccessException
and PathTooLongException
error in reference to my previous question