Files and Directories
suggest changeGet all files in a directory
var filePaths = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
Directory.GetFiles returns the full paths as a string[]. DirectoryInfo.GetFiles is the API that returns FileInfo[]. On .NET Core and later, "*.*" matches only names that contain a dot; "*" matches every name.
Get files with a specific extension
var filePaths = Directory.GetFiles(path, "*.pdf", SearchOption.AllDirectories);
Returns the full paths of files in the directory, and its subdirectories, whose names match the pattern.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents