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 sea
As per my understanding, this can be done in two ways :
1) You can use Directory Class with Getfiles method and traverse across all files to check our required extension.
Directory.GetFiles("your_folder_path)[i].Contains("*.txt")
2) You can use Path Class with GetExtension Method which takes file path as a parameter and verifies the extension.To get the file path, just have a looping condition that will fetch a single file and return the filepath that can be used for verification.
Path.GetExtension(your_file_path).Equals(".json")
Note : Both the logic has to be inside a looping condition.