Answer the question
In order to leave comments, you need to log in
How to do a search in C# for directories, with a list of files for the specified extensions?
Good afternoon, I can’t figure out how to search in C # for directories, including nested directories, specifying the file extensions to search, and entering the paths of these files into a text document.
there is a code:
static List<string> files = new List<string>();
public static void GetAllFiles(string rootDirectory, string fileExtension, List<string> files)
{
string[] directories = Directory.GetDirectories(rootDirectory);
files.AddRange(Directory.GetFiles(rootDirectory, fileExtension));
foreach (string path in directories)
GetAllFiles(path, fileExtension, files);
}
static void Main(string[] args)
{
GetAllFiles(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "*.txt", files);
StreamWriter WriteErrorlog = new StreamWriter(DateTime.Now.ToString(@"MM\.dd\.yyyy") + ".log", true);
foreach (string ListItem in files)
WriteErrorlog.Write(ListItem + "\r\n");
WriteErrorlog.Close();
Console.ReadKey();
}
Answer the question
In order to leave comments, you need to log in
similar:
https://www.myfonts.com/fonts/linotype/icone-lt/ex...
https://www.myfonts.com/fonts/linotype/icone-lt/ex...
search itself:
https ://www.myfonts.com/WhatTheFont/results?ch%5B0...
Use Directory.GetFiles .
For multiple extensions, you can either call the method multiple times or use Directory.EnumerateFiles along with LINQ.
string[] fileNames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".txt") || s.EndsWith(".jpg"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question