LINQ or Lambda for two foreach query I have a Document Name Table in my SQL database and Files in the Content folder.
I have two lists: ListOfFileNamesSavedInTheDB and ListOfFileNamesInTheFolder.

Basically, I am getting all file names saved in the Database and checking if it exists in the Folder, and if not, delete the file name from the database.

 var clientDocList = documentRepository.Documents.Where(c =&gt; c.ClientID == clientID).ToList();

 if (Directory.Exists(directoryPath))
            {
                string[] fileList = Directory.GetFiles(directoryPath).Select(Path.GetFileName).ToArray();
                bool fileNotExist = false;
                foreach (var file in fileList)
                {
                    foreach(var clientDoc in clientDocList)
                    {
                        if (clientDoc.DocFileName.Trim().ToUpper()==file.ToUpper().Trim())
                        {
                            fileNotExist = false;
                            break;
                        }
                    }

                    if (fileNotExist)
                    {
                        //Delete file name from Database
                    }
                }
            }


The code I have written works fine, this inquiry being purely for educational purposes. I want to know how others would do this better and cleaner. I especially hate the way I use two for loops to get data. There has to be a more efficient way.
First thing I'd suggest is make the 2 lists the same type(string).  Now the file list can be an exclusion list that contains only the filenames that aren't in the database.  Something like this should work:

    var clientDocList = documentRepository
        .Documents
        .Where(c =&gt; c.ClientID == clientID)
        .Select(d =&gt; d.DocFileName
        .Trim()
        .ToUpper()).ToList();

    var fileExclusionList = Directory
        .GetFiles(directoryPath)
        .Select(x =&gt; Path.GetFileName(x)
        .Trim()
        .ToUpper())
        .Except(clientDocList).ToArray();