Hello all
I have some path , and i want to get from it only the subdirectories paths (i mean only paths that under them where not found another directories only files).
Any smart way to do so ?
Thanks a lot.
Hello all
I have some path , and i want to get from it only the subdirectories paths (i mean only paths that under them where not found another directories only files).
Any smart way to do so ?
Thanks a lot.
You can use the Directory.GetDirectories method.
However I'm not sure I understood your question correctly... could you clarify ?
DirectoryInfo dInfo = new DirectoryInfo(<path to dir>);
DirectoryInfo[] subdirs = dInfo.GetDirectories();
It is my understanding that you want to list the subdirectories below a given path that contain only files.
static IEnumerable<string> GetSubdirectoriesContainingOnlyFiles(string path)
{
return from subdirectory in Directory.GetDirectories(path, "*", SearchOption.AllDirectories)
where Directory.GetDirectories(subdirectory).Length == 0
select subdirectory;
}