Pick 25 files in alphanumeric order from a folder

  • Thread starter Thread starter Reason101
  • Start date Start date
R

Reason101

Guest
Hi, my requirement is I need to pick only 25 files from a folder which may have over 500 files.

When the process is triggered, the number'ed files needs to be picked first then alphabets.

With below code, it is triggering but not able to pick only those ordered 25 files, All files are getting picked.

Please advise what am I doing wrong ?



string sourceFile = @"path\";
var directory = new DirectoryInfo(sourceFile);

var files = directory.GetFiles()
.Where(x => x.Name.EndsWith(".pdf"))
.OrderBy(x => x.GetName)
.Take(25).ToList();


foreach (FileInfo file in files)
{
string extention = System.IO.Path.GetExtension(file.Name);
System.IO.File.Move(sourceFile + file.Name, sourceFile + file.Name.Replace(extention,".txt"));
}




Reason101

Continue reading...
 
Back
Top