I have a Python script that creates PDF Map Books from pre-existing map PDFs, created in ArcGIS Pro. The PDF file names end with the month abbreviation and year they are associated with (example: CACumulativeSumWithin3000_SanBruno_Dec2017.pdf). I want to order the PDFs in the Map Book based on these final 7 charcacters, but the problem is it orders the PDFs alphabetically, so Apr2018 is first instead of Jan2018.
How can I order these PDFs using the month abbreviation and year?
Here is my code:
import arcpy import os arcpy.env.workspace = r"E:\arcGIS_Shared\Python\Export\Cumulative_CA2" path = r"E:\arcGIS_Shared\Python\Export\Cumulative_CA2" ### Create PDF Map Book File CApdfPath = os.path.join(path, 'SanBruno_CumulativeHeatMaps.pdf') CApdfDoc = arcpy.mp.PDFDocumentCreate(CApdfPath) ### List all files in the output folder CApdfList = arcpy.ListFiles( "CACumulativeSumWithin3000_SanBruno_*") ### Add market title page to the newly created PDF document CApdfDoc.appendPages(os.path.join(path, "CATitlePage.pdf")) ### Append market specific pages to the PDF for CApdf in CApdfList: print(CApdf) CApdfDoc.appendPages(r"E:\arcGIS_Shared\Python\Export\Cumulative_CA2\%s"%CApdf) print(CApdf) CApdfDoc.saveAndClose()