plist appended to folder from listworkspaces

923
3
Jump to solution
08-31-2014 06:28 PM
AllanMills
New Contributor III

I've got a tool I'm working on that recursively iterates through workspaces using arcpy. For each workspace it looks for rasters and notes details about them before looking through any workspaces under the current workspace. For the test data I'm using there is also installer for the Mac and Windows version of Adobe Acrobat amongst it. When my tool gets up to: acrobat\mac\Adobe Reader 6.0\Adobe Reader 6.0.app\Contents\Plug-ins\Multimedia.acroplugin\Contents\MacOS\MPP\QuickTime.mpp\Contents I use ListWorkspaces and I expect to get the subfolders MacOS and Resources. But instead it tells me the workspaces are named plistMacOS and plistResources.

ie. (Have changed workspace path slightly)

>>> arcpy.env.workspace = r"k:\acrobat\mac\Adobe Reader 6.0\Adobe Reader 6.0.app\Contents\Plug-ins\Multimedia.acroplugin\Contents\MacOS\MPP\QuickTime.mpp\Contents"

>>> allWorkspaces = arcpy.ListWorkspaces("*", "All")

>>> for currentWorkspace in allWorkspaces:

...     print currentWorkspace

...    

plistMacOS

plistResources

In the folder I'm checking there is a file called Info-macos.plist which I assume has something to do with it.

The problem is these workspace names aren't valid so when I try to search them I get an error.

Any ideas what is causing this and how to work around this? I could check the workspace exists but I feel I shouldn't have to.

0 Kudos
1 Solution

Accepted Solutions
DaveBarrett
Occasional Contributor

if your specifically trying to look at rasters within a workspace you should consider using arcpy.da.Walk which was added at 10.1 sp1

this behaves much like the os.walk in python but allows for datatype filters. The tool will recurse through sub directories. Take a look at the link below for examples

http://resources.arcgis.com/en/help/main/10.2/#/Walk/018w00000023000000/

Hope this helps

Dave

View solution in original post

0 Kudos
3 Replies
ChrisMathers
Occasional Contributor III

While I appreciate esri trying to work in as much functionality as they can to arcpy so its a "one stop shop" of sorts, I feel like you should just use existing standard modules in python for this task. os.walk goes down a directory tree and for each directory yields a tuple of (dirpath, dirnames, filenames) If you do whats below it will print each directory name then move on to the next directory. The arcpy tool is going to give you results for things like database connection files and geodatabases but you can add logic to the loop to recognize that anything with the .sde or .gdb extensions are workspaces and not just files and folders.

for (dirpath, dirnames, filenames) is os.walk(top_dir):

     if len(dirnames):

          print (dirnames)

0 Kudos
DaveBarrett
Occasional Contributor

if your specifically trying to look at rasters within a workspace you should consider using arcpy.da.Walk which was added at 10.1 sp1

this behaves much like the os.walk in python but allows for datatype filters. The tool will recurse through sub directories. Take a look at the link below for examples

http://resources.arcgis.com/en/help/main/10.2/#/Walk/018w00000023000000/

Hope this helps

Dave

0 Kudos
AllanMills
New Contributor III

Thanks. I had switched to os.walk eventually as I found even stranger problems later on, like when I put an existing directory in a subdirectory to see if it had problems with path name length. It started complaining about workspaces it found not being there which was correct since they really weren't there.

0 Kudos