How to copy selected folders C#?

It is necessary to copy folders with files in them.
For example, there is a function:
void perebor_updates(begin_dir string, string end_dir)
{
 Dir_inf DirectoryInfo = new DirectoryInfo(begin_dir);
 foreach (DirectoryInfo dir in dir_inf.GetDirectories())
{
 if (Directory.Exists(end_dir + "\\" + dir.Name) != true)
{
 Directory.CreateDirectory(end_dir + "\\" + dir.Name);
}

 perebor_updates(dir.FullName end_dir + "\\" + dir.Name);
}

 foreach (string file in Directory.GetFiles(begin_dir))
{
 filik string = file.Substring(file.LastIndexOf('\\'), file.Length - file.LastIndexOf('\\'));
 File.Copy(file, end_dir + "\\" + filik, true);
}
 }

I need to go for all directories
foreach (DirectoryInfo dir in dir_inf.GetDirectories())

but only on selected, that is, those which I will pass to the function.
For example, set the directory there are folders with files, I give to the function only the folders which you want to copy.
June 5th 19 at 21:51
1 answer
June 5th 19 at 21:53
Solution
At the entrance IEnumerable or IEnumerable. Then:
void perebor_updates(IEnumerable<directoryinfo> dirs)
{
 foreach(var dir in dirs)
...
}</directoryinfo>

or
void perebor_updates(IEnumerable<string> dirNames)
{
 foreach(var name in dirNames)
{
 var dir = new DirectoryInfo(name);
...
{
...
}</string>


And then you have a recursive function that takes one folder as a parameter and perform some action.
If you're going to copy a lot of folders, such as a disk, don't use recursion. - Alize_Moen commented on June 5th 19 at 21:56

Find more questions by tags C#