C# Program to Search Directories and List Files Last Updated : 01 Nov, 2021 Comments Improve Suggest changes Like Article Like Report Given files and directories, now our task is to search these files and directories using C#. So to do this task we use the following methods: 1. SearchOption: This method is used to specify whether to search the current directory or the current directory with all subdirectories. Syntax: public enum SearchOption It will take two fields that is AllDirectories and TopDirectoryOnly. AllDirectories field is used to perform the search that contains the current directory and all its subdirectories in a search operation. And TopDirectoryOnly field is used to search only in the main directory. 2. GetFiles: This method is used to return the name of the files present in a particular directory or subdirectory. Or we can say that it returns the name along with the path of the files that are available in the given directory. 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. Approach 1. Read the directory and search in C drive A folder using searchoption AllDirectories keyword list = Directory.GetFiles("C:\\A\\","*.*", SearchOption.AllDirectories) 2. Iterate through the list and display using foreach loop foreach (string file in list) { Console.WriteLine(file); } Example: In this example, we are displaying the list of file names along with their path by searching in the C drive - A directory. C# // C# program to search directories and list files using System; using System.IO; class GFG{ static void Main() { // Here we search the file present in C drive // and A directory. Using SearchOption string[] list = Directory.GetFiles("C:\\A\\", "*.*", SearchOption.AllDirectories); // Display the file names // Present in the A directory foreach (string file in list) { Console.WriteLine(file); } } } Output: C:\A\file.txt Comment More infoAdvertise with us Next Article C# Program For Listing the Files in a Directory M manojkumarreddymallidi Follow Improve Article Tags : C# CSharp-programs Similar Reads C# Program For Listing the Files in a Directory Given files, now our task is to list all these files in the directory using C#. So to do this task we use the following function and class: DirectoryInfo: It is a class that provides different types of methods for moving, creating, and enumerating through directories and their subdirectories. You ca 2 min read Python List All Files In Directory And Subdirectories Listing all files in a directory and its subdirectories is a common task in Python, often encountered in file management, data processing, or system administration. As developers, having multiple approaches at our disposal allows us to choose the most suitable method based on our specific requiremen 5 min read How to List all Files and Directories in FTP Server using Python? FTP ( File Transfer Protocol ) is set of rules that computer follows to transfer files across computer network. It is TCP/IP based protocol. FTP lets clients share files. FTP is less secure because of files are shared as plain text without any encryption across the network. It is possible using pyt 2 min read Obtain List of Directories in R A directory or folder in the R programming language may contain other directories. It is possible to access the list of all the directories using base methods in R and return them as a list of folders. The list.dirs() method in R language is used to retrieve a list of directories present within the 3 min read Read all Files in Directory using R To list all files in a directory in R programming language we use list.files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories. If no files are present in the directory, 2 min read Python - List files in directory with extension In this article, we will discuss different use cases where we want to list the files with their extensions present in a directory using python. Modules Usedos: The OS module in Python provides functions for interacting with the operating system.glob: In Python, the glob module is used to retrieve fi 3 min read Like