Skip to content

Instantly share code, notes, and snippets.

@alaawahbah
Last active July 4, 2023 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaawahbah/3c66e2f78340eb925b7d2182e9800c7f to your computer and use it in GitHub Desktop.
Save alaawahbah/3c66e2f78340eb925b7d2182e9800c7f to your computer and use it in GitHub Desktop.
void Main()
{
// var asd = Directory.GetDirectories(@"D:\MyWork", "*.*", SearchOption.AllDirectories);
//
// var asdad1 = asd.Where(t =>t.EndsWith("node_modules") && (t.IndexOf("node_modules")==t.LastIndexOf("node_modules") && t.IndexOf("node_modules")!=-1)).ToList();
// asdad1.Dump();
GetRootDirectoryByName(@"D:\MyWork","node_modules").Dump();
GetAllSubDirectory(@"D:\MyWork").Dump();
}
List<string> GetRootDirectoryByName(string pathToSearch,string directoryName){
var dirs = Directory.GetDirectories(pathToSearch, "*.*", SearchOption.AllDirectories);
return dirs.Where(t =>t.EndsWith(directoryName) && (t.IndexOf(directoryName)==t.LastIndexOf(directoryName) && t.IndexOf(directoryName)!=-1)).ToList();
}
List<string> GetAllSubDirectory(string path){
var dirs = Directory.GetDirectories(path, "*.*", SearchOption.AllDirectories);
return dirs.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment