lundi 30 novembre 2020

How to find in a folder the newest file following a pattern but also excluding some files

I know that this code works for finding the newest file

var directory = new DirectoryInfo(tbxDir.Text);
if (Directory.Exists(tbxDir.Text))
{
    var NewestFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First();
    ...
}

What I can't imagine is how to extend it to:

  1. Use a pattern: e.g. a*c.txt
  2. Exclude a list of files (e.g. lst = { "log.txt", "ccc.txt", ...}

Can that be done with a Linq expression? Thanks for helping Patrick

Aucun commentaire:

Enregistrer un commentaire