Hi,
The following code takes PDFs and appends them to a title page, creating a PDF MapBook. However, I can't figure out how to get the PDFs in the right order. I want the PDFs to be ordered by the month and year specified in the files (last 6 characters), rather than just alphabetical order of the whole file name. I am specifying the month using its numeric value (Example: CTDiscreteSumWithin4000_Avon_2017_5), I don't know whether than makes things easier or harder.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\arcGIS_Shared\Python\Export\Discrete_CT"</SPAN>
path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\arcGIS_Shared\Python\Export\Discrete_CT"</SPAN>
<SPAN class="comment token">### Create the PDF MapBook file</SPAN>
CTpdfPath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Avon_DiscreteHeatMaps.pdf'</SPAN><SPAN class="punctuation token">)</SPAN>
CTpdfDoc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>PDFDocumentCreate<SPAN class="punctuation token">(</SPAN>CTpdfPath<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">###List all files to be added to MapBook</SPAN>
CTpdfList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CTDiscreteSumWithin4000_Avon*"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### Add market title page to the newly created PDF document</SPAN>
CTpdfDoc<SPAN class="punctuation token">.</SPAN>appendPages<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CTTitlePage.pdf"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### Append market specific pages to the PDF</SPAN>
<SPAN class="keyword token">for</SPAN> CTpdf <SPAN class="keyword token">in</SPAN> CTpdfList<SPAN class="punctuation token">:</SPAN>
CTpdfDoc<SPAN class="punctuation token">.</SPAN>appendPages<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\arcGIS_Shared\Python\Export\Discrete_CT\%s"</SPAN><SPAN class="operator token">%</SPAN>CTpdf<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>CTpdf<SPAN class="punctuation token">)</SPAN>
CTpdfDoc<SPAN class="punctuation token">.</SPAN>saveAndClose<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Any help/advice would be appreciated. Thanks.