문제

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"))
{
    ...
}
도움이 되었습니까?

해결책

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")))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top