0

I want to order the file list according to the file name in ascending order to merge these all files. This is not only two files. More than 100 files in there my file names like 0.pdf,1.pdf,2.pdf,3.pdf …etc

This is my VB.NET Code:

Dim files = Directory.GetFiles(directoryName, "*.*", SearchOption.TopDirectoryOnly).OrderBy(Function(f) New FileInfo(f).FullName)
For Each pdf In files
    Using pdfDoc As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open(pdf, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)

        For i As Integer = 0 To pdfDoc.PageCount - 1
            targetDoc.AddPage(pdfDoc.Pages(i))
        Next
    End Using
Next
targetDoc.Save(directoryName + "\merged.pdf")

I tried using Dim files = Directory.GetFiles(directoryName, "*.*", SearchOption.TopDirectoryOnly).OrderBy(Function(f) New FileInfo(f).FullName) but it gives me the wrong output like this 0.pdf,1.pdf,11.pdf,12.pdf,...,2.pdf.21.pdf,22.pdf...etc

Please help me to order these files according to the filename in ascending order. Thank you

delma wax
  • 13
  • 2

0 Answers0