Question

For some reason, my code below isnt working. I have confirmed that there is both .idx and .log files within the folder. Can someone please help?

Thanks.

List<string> subDirList = new List<string>(Directory.GetFiles(srcPath, "*"));

if (subDirList.Contains(".idx") && subDirList.Contains(".log"))
{
    ...
}
Était-ce utile?

La solution

subDirList contains filenames, not only extensions. That's why you're finding nothing.

You should probably use Any with EndsWith:

if (subDirList.Any(x => x.EndsWith(".idx")) && subDirList.Any(x => x.EndsWith(".log")))

Or if .idx and .log are not extensions, but just part of filename, use Contains:

if (subDirList.Any(x => x.Contains(".idx")) && subDirList.Any(x => x.Contains(".log")))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top