Reputation: 2564
I have this code for looping through folders in a location, but I am getting some error I can't understand, here's the code
var directoryNames = Directory.EnumerateDirectories(filePath).Where(dir => dir.EndsWith(".user"));
foreach (var directoryName in directoryNames)
{
// some stuff
}
I get this error
'System.IO.Directory' does not contain a definition for 'EnumerateDirectories'
If this is something to do with the Framework version (my project has Framework 2.0, lowest possible so it can install easier on all machines), can you please:
or
Upvotes: 0
Views: 1559
Reputation: 54897
EnumerateDirectories
was introduced in .NET 4.0. For .NET 2.0, you could use GetDirectories
instead. You can specify your filter as a search pattern; this would cause the filtering to be performed by the filesystem itself.
var directoryNames = Directory.GetDirectories(filePath, "*.user");
foreach (var directoryName in directoryNames)
{
// ...
}
Upvotes: 3