<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Handy script to analyze all python scripts in a directory for python 3.x in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1153043#M52706</link>
    <description>&lt;P&gt;I just tested this - it looks like your code writes adjacent to the output directory? Maybe something like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

searchDir = r'../some/path'
outputPath = r'../some/path'

Scripts = {}
for subdir, dirs, files in os.walk(searchDir):
    for a in files:
        if a.endswith(".py"):
            FileName = os.path.splitext(a)[0]
            path = os.path.join(subdir, a)
            Scripts[FileName] = path

for b in Scripts:
    name = b
    filepath = Scripts[b]
    outfile = os.path.join(outputPath, name + ".txt")
    arcpy.AnalyzeToolsForPro_management(filepath, outfile)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;It also seemed like a fun code golf. Here's an equivalent that adds simple increment to file name to avoid duplicate collisions (e.g. multiple __init__.py)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from os.path import join, split, splitext
from pathlib import Path

from arcpy.management import AnalyzeToolsForPro

in_path = r'.../some/path'
out_path = r'.../some/path'

for i, path in enumerate(filter(lambda p: p.suffix in {".py", ".pyt", ".tbx"}, Path(in_path).rglob("*"))):
    AnalyzeToolsForPro(path.__str__(), join(out_path, splitext(split(path)[1])[0] + f'{i}.txt'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/4568580/python-glob-multiple-filetypes" target="_self"&gt;Stackoverflow link&lt;/A&gt;&amp;nbsp;discussing the common walk/glob path task.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2022 19:32:06 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-03-11T19:32:06Z</dc:date>
    <item>
      <title>Handy script to analyze all python scripts in a directory for python 3.x</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152775#M52660</link>
      <description>&lt;P data-unlink="true"&gt;Today I began the process to upgrade our python scripts from 2.7 to 3.x and I wanted to utilize the &lt;A title="Analyze Tools for Pro" href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/analyzetoolsforpro.htm" target="_blank" rel="noopener"&gt;Analyze Tools for Pro&lt;/A&gt;&amp;nbsp;&amp;nbsp;but I didn't want to have to search for every python script in my file share to then manually run it in the tool. Therefore I built this script to walk through a directory, find all the python scripts, and then iterate them through the tool automatically. I felt if I wanted to use this script someone else might want it as well! Hope this helps!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

searchDir = "\\\\{server}\\{share}\\{folder}"
outputPath = "C:\\Users\\{user name}\\Desktop\\Tool Analysis\\"

Scripts = {}
for subdir, dirs, files in os.walk(searchDir):
    for a in files:
        if a.endswith(".py"):
            FileName = os.path.splitext(a)[0]
            path = os.path.join(subdir,a)
            Scripts[FileName]= path

for b in Scripts:
    name = b
    filepath = Scripts[b]
    outfile = outputPath+name+".txt"
    arcpy.AnalyzeToolsForPro_management(filepath, outfile)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 22:56:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152775#M52660</guid>
      <dc:creator>Greg_Mattis</dc:creator>
      <dc:date>2022-03-10T22:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Handy script to analyze all python scripts in a directory for python 3.x</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152794#M52665</link>
      <description>&lt;P&gt;Hey! Thanks for saving us some work! Mucho appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 00:19:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152794#M52665</guid>
      <dc:creator>GeoJason</dc:creator>
      <dc:date>2022-03-11T00:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Handy script to analyze all python scripts in a directory for python 3.x</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152824#M52672</link>
      <description>&lt;P&gt;And if you want to check Python and custom&amp;nbsp;toolboxes as well, you could:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for subdir, dirs, files in os.walk(searchDir):
    for a in files:
        if os.path.splitext(a)[-1] in (".py", ".pyt", ".tbx"):
            etc...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 03:42:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152824#M52672</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2022-03-11T03:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Handy script to analyze all python scripts in a directory for python 3.x</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152954#M52694</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10780"&gt;@Luke_Pinner&lt;/a&gt;&amp;nbsp;That is a great add! We don't do any custom tool boxes here definitely a great add for those who do.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 15:45:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1152954#M52694</guid>
      <dc:creator>Greg_Mattis</dc:creator>
      <dc:date>2022-03-11T15:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Handy script to analyze all python scripts in a directory for python 3.x</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1153043#M52706</link>
      <description>&lt;P&gt;I just tested this - it looks like your code writes adjacent to the output directory? Maybe something like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os

searchDir = r'../some/path'
outputPath = r'../some/path'

Scripts = {}
for subdir, dirs, files in os.walk(searchDir):
    for a in files:
        if a.endswith(".py"):
            FileName = os.path.splitext(a)[0]
            path = os.path.join(subdir, a)
            Scripts[FileName] = path

for b in Scripts:
    name = b
    filepath = Scripts[b]
    outfile = os.path.join(outputPath, name + ".txt")
    arcpy.AnalyzeToolsForPro_management(filepath, outfile)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;It also seemed like a fun code golf. Here's an equivalent that adds simple increment to file name to avoid duplicate collisions (e.g. multiple __init__.py)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from os.path import join, split, splitext
from pathlib import Path

from arcpy.management import AnalyzeToolsForPro

in_path = r'.../some/path'
out_path = r'.../some/path'

for i, path in enumerate(filter(lambda p: p.suffix in {".py", ".pyt", ".tbx"}, Path(in_path).rglob("*"))):
    AnalyzeToolsForPro(path.__str__(), join(out_path, splitext(split(path)[1])[0] + f'{i}.txt'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/4568580/python-glob-multiple-filetypes" target="_self"&gt;Stackoverflow link&lt;/A&gt;&amp;nbsp;discussing the common walk/glob path task.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 19:32:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/handy-script-to-analyze-all-python-scripts-in-a/m-p/1153043#M52706</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-11T19:32:06Z</dc:date>
    </item>
  </channel>
</rss>

