C # Gets folder all file names

For example, you want to get a file with a .txt extension

//第一种方法
var files = Directory.GetFiles(path, "*.txt");  
             
foreach (var file in files)
    Console.WriteLine(file);
 
//第二种方法
DirectoryInfo folder = new DirectoryInfo(path);
            
foreach (FileInfo file in folder.GetFiles("*.txt"))
{
    Console.WriteLine(file.FullName);
}

The first method is to obtain the corresponding file path

The second method can get into some of the details of the file  

Like "* .txt"   to match the file name and path of the search string. This parameter can contain a valid text path and wildcards (* and?) A combination of characters, but it does not support regular expressions.

I am referring to the preparation of this blog path for their own queries quickly   https://www.cnblogs.com/technology/archive/2011/07/12/2104786.html

Guess you like

Origin www.cnblogs.com/ljknlb/p/11856689.html