Reputation: 7
How can I use two of the following Get Directories? I need to add them into one int, but when I use the following code I just get the same numbers.
var directoryInfo = new System.IO.DirectoryInfo(@"c:\test\");
int directoryCount = directoryInfo.GetDirectories().Length;
var directoryInfo2 = new System.IO.DirectoryInfo(@"c:\test2\");
int directoryCount2 = directoryInfo.GetDirectories().Length;
int directoryCountMain = directoryCount + directoryCount2;
Upvotes: 0
Views: 39
Reputation: 125610
You're missing 2
in directoryCount2
initialization declaration.
You're using directoryInfo.GetDirectories().Length
twice, instead of using directoryInfo2
object when setting directoryCount2
.
var directoryInfo2 = new System.IO.DirectoryInfo(@"c:\test2\");
int directoryCount2 = directoryInfo2.GetDirectories().Length;
Upvotes: 1