ArcGIS profile installation directories

533
5
Jump to solution
02-22-2012 09:50 AM
MathewCoyle
Frequent Contributor
Does anyone know of a way to dynamically find the ArcGIS profile directory without having to code each in explicitly with an if/else? Specifically, I am trying to access the Custom Transformations folder.

For example, I have 9.3.1 on Windows XP or 10.0 on Windows 7 and test doing something like the following

if windows[0] == "6":     trans_dir = os.getenv("USERPROFILE") +os.sep+ r"AppData\Roaming\ESRI\Desktop10.0\ArcToolbox\CustomTransformations" elif windows[0] == "5":     trans_dir = os.getenv("USERPROFILE") +os.sep+ r"Application Data\ESRI\ArcToolbox\CustomTransformations"


But also may run into situations where there is 9.3.1 on Windows 7, or 10.0 on Windows XP. Putting each possibility in seems rather sloppy. Is there a cleaner way to go about this?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Regular Contributor III
How about:

arcpy.GetSystemEnvironment("APPDATA")
or
os.getenv("APPDATA")

and then sort out the

ESRI\Desktop10.0\ArcToolbox\CustomTransformations
or
ESRI\ArcToolbox\CustomTransformations

using

arcpy.GetInstallInfo("DESKTOP")['Version']
or
gp.GetInstallInfo("DESKTOP")['Version']

View solution in original post

0 Kudos
5 Replies
ChrisSnyder
Regular Contributor III
How about:

arcpy.GetSystemEnvironment("APPDATA")
or
os.getenv("APPDATA")

and then sort out the

ESRI\Desktop10.0\ArcToolbox\CustomTransformations
or
ESRI\ArcToolbox\CustomTransformations

using

arcpy.GetInstallInfo("DESKTOP")['Version']
or
gp.GetInstallInfo("DESKTOP")['Version']
0 Kudos
MathewCoyle
Frequent Contributor
That makes it much easier to read, thanks.
0 Kudos
curtvprice
MVP Esteemed Contributor
Here's some reusable code:

import arcpy
import os
def ArcGISProfile(profilePath=None):
    """ArcGIS Windows user profile path"""
    APPDATA = arcpy.GetSystemEnvironment("APPDATA")
    if arcpy.GetInstallInfo("DESKTOP")['Version'].find("10") == -1:
       path = os.path.join(APPDATA,"ESRI")
    else:
       path = os.path.join(APPDATA,"ESRI/Desktop10.0/")
    return os.path.realpath(os.path.join(path,profilePath))

print ArcGISProfile("ArcToolbox\CustomTransformations")


This returns (on XP):

C:\Documents and Settings\cprice\Application Data\ESRI\Desktop10.0\ArcToolbox\CustomTransformations
0 Kudos
ChrisSnyder
Regular Contributor III
Still doesn't get rid of the need for the conditional statement though... That said, I don't think there is a way to "directly" get the path you are looking for.

This might be handy: http://en.wikipedia.org/wiki/Environment_variable#Default_Values_on_Microsoft_Windows
0 Kudos
MathewCoyle
Frequent Contributor
I had thought there would be some behind the curtain voodoo that could be accessed to go directly to the CustomTransformations folder, since whenever you use the Project tool with valid parameters the custom transformation will come up as an option. So somewhere out there is a CustomTransformation folder variable, but I guess it isn't accessible.
0 Kudos