How would I search all the files in directory and all its sub directories for a specific extension
Directory.GetFiles(path, ".txt", SearchOption.AllDirectories);
The code above returns no files
How would I search all the files in directory and all its sub directories for a specific extension
Directory.GetFiles(path, ".txt", SearchOption.AllDirectories);
The code above returns no files
you need to use wild card notation
Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
in your case you're searching for files ".txt" name, instead you need tell to API to retrieve to you all files that has txt
extension.
Because you're searching literally for the file named .txt
Use a wildcard character like so: *.txt
and it should pull up any .txt
files.
See documentation: http://msdn.microsoft.com/en-us/library/ms143316.aspx
I believe its your search pattern or second parameter. should be "*.txt".
Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);
The filter needs to be "*.txt":
Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories);