env.workspace - how to navigate "up" one folder?

692
1
Jump to solution
03-25-2013 08:42 AM
JT2
by
New Contributor II
I am familiar with setting the env.workspace parameter in arcpy. That allows me to work within subfolders of the workspace, eg:

layer = arcpy.mapping.Layer("Sub\Test.shp")


But how do I do the opposite, ie go up one level in the folder tree?

This doesn't work:

layer = arcpy.mapping.Layer("..\Test.shp")


Is there an easy way to go up a level from the workspace path? Or is it not possible?

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
I don't think you can, how you envision it in any case. You can walk your workspace back one level and use the full path as a variable though.

up_one_dir = arcpy.env.workspace.rsplit(os.sep, 1)[0]

View solution in original post

0 Kudos
1 Reply
MathewCoyle
Frequent Contributor
I don't think you can, how you envision it in any case. You can walk your workspace back one level and use the full path as a variable though.

up_one_dir = arcpy.env.workspace.rsplit(os.sep, 1)[0]
0 Kudos