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]
except OSError as exception:
if exception.errno != errno.EEXIST:
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\", line 10, in <module>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\", 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.