Search code examples
c#.netfile-extensiongetfilesfilepattern

How can I make GetFiles() exclude files with extensions that start with the search extension?


I am using the following line to return specific files...

FileInfo file in nodeDirInfo.GetFiles("*.sbs", option)

But there are other files in the directory with the extension .sbsar, and it is getting them, too. How can I differentiate between .sbs and .sbsar in the search pattern?


Solution

  • Try this, filtered using file extension.

      FileInfo[] files = nodeDirInfo.GetFiles("*", SearchOption.TopDirectoryOnly).
                Where(f=>f.Extension==".sbs").ToArray<FileInfo>();