title: How to create folders from a list of files by last modified date month wise c#
body: <p>I want to create folders month wise from a list of files.</p>
  
  <p>I tried below code.</p>
  
  <pre><code>var files = directory.GetFiles()
                    .Where(file =&gt; file.LastWriteTime.Month == date.Month -1);
  
               //create folder for the files (With MonthName)
               var year = files.Select(j =&gt; j.LastWriteTime.Year).FirstOrDefault();
               var month = files.Select(j =&gt; j.LastWriteTime.Month).FirstOrDefault();
               var newFolderPath = year.ToString() + month.ToString();
  
               var destinationDirec = System.IO.Directory.CreateDirectory(directory + newFolderPath);
  
               foreach (var f in files)
               {                 
  
                 // var destFile = System.IO.Path.Combine(directory, destinationDirec);
                   var path = Path.Combine(destinationDirec.FullName, f.Name);
  
                   if (!File.Exists(path))
                   {
                       System.IO.File.Move(f.FullName, path);
                   }                  
  
               }               
  </code></pre>
  
  <p>The above code gave the list of files for the last month. But I want create folders for the files which are older than the current month.
  Can anyone give me a solution?</p>