c# - Get folders that contain a certain number of directories -
so right have list of directories wanted through regex pattern , linq filtering. need way folders contain number of directories , skip ones without 1 , how check if directory info empty or not . suggestions ? have far
directoryinfo root = new directoryinfo(@"c:\users\jphillips\desktop\test"); var dirs = new list(); dirs = root.getdirectories("*", searchoption.alldirectories).where(d => reg.ismatch(d.name)).where((d => !d.fullname.endswith("tests"))).where(d => d.getfiles().length > 3).tolist();
foreach (directoryinfo dir in dirs) { console.writeline(dir.fullname); }
can tell me how filter here, , * mean in directories function
heres starting point suppose:
var diprojects = new directoryinfo(@"c:\projects"); var subfolders = diprojects.getdirectories(); (var = 0; < subfolders.length; i++) { console.writeline(string.format("[{0}] {1}, directories = {2}, files = {3}" , , subfolders[i].fullname , subfolders[i].getdirectories().length , subfolders[i].getfiles().length)); }
the following line gets number of directories within specified folder, can check see if equal 0 or ever value need check against
subfolders[i].getdirectories().length
also can use following number files in subdirectory
subfolders[i].getfiles().length
if both subfolders[i].getdirectories().length
, subfolders[i].getfiles().length
0 can assume subdirectory empty. should able use code template want.
Comments
Post a Comment