Given a folder path (like C:\Random Folder
), how can I find a file in it that holds a certain extension, like txt
? I assume I'll have to do a search for *.txt
in the directory, but I'm not sure how I'm supposed to start this search in the first place.
Open Control Panel > Appearance and Personalization. Now, click on Folder Options or File Explorer Option, as it is now called. Select the View tab. In this tab, under Advanced Settings, you will see the option Hide extensions for known file types.
Look at the System.IO.Directory
class and the static method GetFiles
. It has an overload that accepts a path and a search pattern. Example:
string[] files = System.IO.Directory.GetFiles(path, "*.txt");
You could use the Directory class
Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With