0

What is the syntax for searching all files that don't have a 0 in file name at a specific position In my case i want to search for all files that doesnt have 0 in 11th position of filename in place of " * " as shown below

string[] files = System.IO.Directory.GetFiles(sourcePath, fileName + "_*"); 
adi126
  • 1
  • 2
  • Take a look at this other Q&A: http://stackoverflow.com/questions/13022988/searching-for-a-file-on-remote-machine-wmi-c-sharp Maybe WMI which uses SQL-like syntax can do the job – Matías Fidemraizer Dec 10 '15 at 20:40
  • How does "doesnt have 0 in 11th position" relate to `fileName + "_*"`? Are you saying that `filename` is always nine characters long? Some example filenames would help. – Andrew Morton Dec 10 '15 at 21:31

2 Answers2

1

Can't do a "not", but next best thing would be to filter with LINQ.

string[] files = System.IO.Directory.GetFiles(sourcePath, fileName + "_*")
  .Where(x => !Path.GetFileName(x).StartsWith(fileName + "_0"))
  .ToArray();
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
0

Or you can try like in following expression:

        string path = @"C:\";
        string parameter = "SomeParameter";
        string[] files = Array.FindAll(Directory.GetFiles(path), x => !Path.GetFileName(x).StartsWith(parameter));

        foreach (string file in files)
        {
            Console.WriteLine(file);
        }
kat1330
  • 5,134
  • 7
  • 38
  • 61