![]() |
VOOZH | about |
C# is a general-purpose, object-oriented programming language pronounced as “C Sharp”. It is a lot syntactically similar to Java and is easy for users who have knowledge of C, C++, or Java. In this article, we will learn How can we use C# to search the sub-Directory in a given Directory. So for this task, we use the following methods:
1. SearchOption: This method is used to tell the compiler whether to do our search in the current directory or the current directory with all subdirectories.
Syntax:
public enum SearchOption
It will take two fields:
2. GetFiles: When we need to fetch the names of the files present in a directory or subdirectory then the GetFiles function is used. It returns a string array containing the names of the files.
Syntax:
public static string[] GetFiles (string path);
Where the path is the directory to search. This string is not case-sensitive. Here the path can be the relative or absolute path.
Example 1:
Output:
no
Example 2:
Output:
yes