I've managed to get files out of "root" folder subdirectories, but I also get files from these subdirectories directories2, which I don't want to.
Example: RootDirectory>Subdirectories (wanted files)>directories2 (unwanted files)
I've used this code:
public void ReadDirectoryContent()
{
var s1 = Directory.GetFiles(RootDirectory, "*", SearchOption.AllDirectories);
{
for (int i = 0; i <= s1.Length - 1; i++)
FileInfo f = new FileInfo(s1[i]);
. . . etc
}
}
You have to change
SearchOption.AllDirectories
toSearchOption.TopDirectoryOnly
, because the first one means that it gets the files from the current directory and all the subdirectories.EDIT:
Try this :
The idea is to first select 1st level of subdirectories, then "aggregate" all files using Enumerable.SelectMany method