-4

How can I exclude all .txt file and doc file in a folder?

I am able to get all the file but unable to exclude .txt file and .doc files.

foreach (string f in Directory.GetFiles(@readpath))
            {
                List<string> list = new List<string>();
                list.Add(f);

                for (listcount = 0; listcount < list.Count; listcount++)
                {
                    path2 = list[listcount];
                    creationdate = File.GetCreationTime(path2);
                    modidate = File.GetLastWriteTime(path2);

                }
                chkchecksum();
            }
ale
  • 10,012
  • 5
  • 40
  • 49
  • 1
    I think this has been asked before, see http://stackoverflow.com/questions/755166/exclude-certain-file-extensions-when-get-files-from-a-directory , if not please explain what else you need =) – DerApe Jul 03 '14 at 05:32

1 Answers1

0

Replace

foreach (string f in Directory.GetFiles(@readpath))

With

foreach (string f in Directory.GetFiles(@readpath).Where(f => !(f.EndsWith(".doc", StringComparison.OrdinalIgnoreCase) && !f.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))))
Jonathon Lee
  • 211
  • 1
  • 4