list APRXs in workspace folder

01-23-2019 11:44 AM
MVP Regular Contributor

I'm in the process of migrating my stand-alone python scripts from ArcMap to ArcGIS Pro. Using PyScripter as an IDE, I was able to successfully set up my environment. I'm using Python 3.6.2 that came with Pro 2.1. 

I want to simply list the files in the workspace folder. Line 3 causes an OSError.

import arcpy, os

aprx ="Path\to\folder")

#list the APRXs of the workspace folder
for root, dirs, files, in os.walk(aprx):
    for f in files:
        if f.endswith(".aprx"):
            mxd =, f))
            print("current map being checked is  " + f)

How do I create a variable for the workspace folder for Pro? Here's how I would've done it for ArcMap:

ws = arcpy.env.workspace = r'path\to\folder'
0 Kudos
3 Replies
MVP Honored Contributor

It looks like you should reference a aprx file, not directory. For example:

aprx ="C:\Projects\blank.aprx")

Also, os.walk doesn't specifically have anything to do with ArcGIS or arcpy. Pass it a plain old directory string. For example:

rootDir = '.'
for dirName, subdirList, fileList in os.walk(rootDir):
MVP Legendary Contributor

that returns a project

from arcpy import mp as MAP  
aprx = MAP.ArcGISProject('c:/Projects/YosemiteNP/Yosemite.aprx')


from arcpy import mp
aprx = mp.ArcGISProject('c:/Projects/YosemiteNP/Yosemite.aprx')

# ---- to start in that folder


MVP Regular Contributor

Thanks for the help.

Apologies if I wasn't too clear. I wanted to list any and all projects (APRXs) in a folder. Sometimes spelling it out answers your own question.

It looks like you can use the same environment variable as you would with ArcPy in ArcMap. This worked:

ws = arcpy.env.workspace = r"path\to\folder"

Whole thing:

import arcpy, os

ws = arcpy.env.workspace = r"path\to\folder"

#list the APRXs of the workspace folder
for root, dirs, files, in os.walk(ws):
    for f in files:
        if f.endswith(".aprx"):
            print("current project being checked is  " + f)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos