Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get only first level sub directories C#

I have folder structure like follow

enter image description here

Path of the main folder is

C:\Users\me\Desktop\main_folder\

withing that there can be any number of sub folders with any name.

what i need to do is go in to each of that sub folder and extract the zip files in it.

For this, in powerhsell we can use the path like follow which takes any sub folder in the given folder.

C:\Users\me\Desktop\main_folder\*\*.zip

but how to do this in C# ?

method that i'm trying to use is

System.IO.Directory.GetFiles("C:\Users\me\Desktop\main_folder\*\",
      "*.zip",System.IO.SearchOption.TopDirectoryOnly);
like image 965
Sandaru Avatar asked Nov 24 '16 13:11

Sandaru


1 Answers

Try this:

    string root = @"C:\Users\me\Desktop\main_folder\";

    var files = 
        Directory.EnumerateDirectories(root).SelectMany(
            directory => Directory.EnumerateFiles(directory, "*.zip"));
like image 75
Matthew Watson Avatar answered Sep 24 '22 06:09

Matthew Watson