I'm not sure why this isn't working correctly. I want to export the layouts of the APRX files I have in a folder as PDFs and save them in the same place. It will run with no errors but there is no PDF saved in the outfolder. There is, however, one PDF saved one place back in the path.
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os
rootDir <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"path\to\TestFolder"</SPAN>
outfolder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"path\to\TestFolder"</SPAN>
<SPAN class="keyword token">for</SPAN> dirName<SPAN class="punctuation token">,</SPAN> subdirList<SPAN class="punctuation token">,</SPAN> fileList <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>walk<SPAN class="punctuation token">(</SPAN>rootDir<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> file <SPAN class="keyword token">in</SPAN> fileList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> file<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".aprx"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
current_aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>rootDir<SPAN class="punctuation token">,</SPAN> file<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
pdf_name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>outfolder<SPAN class="punctuation token">,</SPAN> file<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">".pdf"</SPAN>
<SPAN class="keyword token">for</SPAN> lyts <SPAN class="keyword token">in</SPAN> current_aprx<SPAN class="punctuation token">.</SPAN>listLayouts<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
lyts<SPAN class="punctuation token">.</SPAN>exportToPDF<SPAN class="punctuation token">(</SPAN>outfolder<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"exporting APRX to PDF: {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>pdf_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> file<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>Here's the print statements in the Interpreter window:
exporting APRX to PDF<SPAN class="punctuation token">:</SPAN> path\to\TestFolder2\MUNICIPAL_LIMITS_A <SPAN class="operator token">-</SPAN> Copy<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>pdf
exporting APRX to PDF<SPAN class="punctuation token">:</SPAN> path\to\TestFolder2\MUNICIPAL_LIMITS_A<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>pdf<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>