AnsweredAssumed Answered

How to implement os.getcwd() in Pro 2.1.2?

Question asked by tpcolson Champion on Jun 4, 2018
Latest reply on Jun 5, 2018 by Dan_Patterson

When attaching the following to a tool box in Pro 2.1.2 and running it: 

 

import os
import errno
import arcpy
curr = dirpath = os.getcwd()
directories = ['Data','Data//GPS','Data//Working','Data//Tabular','Products','Documents', 'Documents//Pics_Graphics']
basedirectory = curr +'//'
for i in range (len (directories)):
newDir = basedirectory + directories[i]
try:
os.makedirs(newDir)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
else:
print ("\nBE CAREFUL! Directory %s already exists." % newDir)

I get the following error: 

 

Start Time: Monday, June 04, 2018 4:10:17 PM
Running script CreateProjectFolders...
Failed script Create Project Folders...
Traceback (most recent call last):
File "C:\temp\Pro_Folder_Structure\NEW_FOLDERS.py", line 10, in <module>
os.makedirs(newDir)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\ArcGIS\\Pro//Data'
Failed to execute (CreateProjectFolders).
Failed at Monday, June 04, 2018 4:10:17 PM (Elapsed Time: 0.06 seconds)

 

 

My assumption is that os.getcwd() would get the directory that the pro project is saved to. curr = dirpath = arcpy.env.workspace doesn't appear to do anything here. 

Outcomes