3

Is there a way to get the current directory opened in ArcCatalog 10.0 using Python? Something like os.getcwd() but instead gives the selected folder on the catalog tree.

Cheers

  • While this seems like an interesting idea, why are you looking for this functionality? If you are looking to loop over all the files in the currently selected directory, no use reinventing the wheel. You can specify a folder parameter in a custom script you write. – Paul Jul 12 '13 at 3:06
  • Hi Paul! What I'm looking for is to use one of the arcpy list fucntions (ListFiles; ListDatasets, ...) to print a list of shps, fcs, ... that are in the directory currently opened in ArcCatalog. Every time I want to do this I need first to copy the path, then paste it to the code. Not too time consuming but still if there was a way to read the current directory opened in ArcCatalog it would greatly simplify the code. Thanks – nafarinha Jul 12 '13 at 11:38
2

Assuming there isn't a way to access the open directory in ArcCatalog (Another issue with this would be if there were two folders open. Would you only want to print out the folder that is currently selected [highlighted?] or every open folder in the tree?), this is probably the easiest way.

This is a super basic script (it's only 3 lines of code!). All you have to do is drag the folder into the script, and it will print out all the images in the directory, like so: enter image description here

If you wanted to get fancy with it, you could add boolean parameters that would allow you to write the names to a text file and/or utilize other list functions.

import arcpy
arcpy.env.workspace = arcpy.GetParameterAsText(0)
[arcpy.AddMessage(image) for image in arcpy.ListDatasets()]
1

I think you are probably looking for arcpy.env.workspace = <path>

Current Workspace (Environment setting)

Current Workspace—The workspace from which inputs are taken and outputs are placed when running tools

  • 2
    I don't think that's the answer because at the help page you cited it says "In ArcCatalog, the Scratch Workspace and Current Workspace environments are not set by default." and an ArcCatalog 10.1 Python window test I just did to print arcpy.env.workspace returned "..\..\Users\Graeme\Documents\ArcGIS\Default.gdb" and not the folder I had open. – PolyGeo Jul 11 '13 at 23:08
  • Well that's better than I can get in ArcCatalog 10.1.1 print arcpy.env.workspace returned None. – Paul Jul 12 '13 at 3:04
  • Agreed, I was thinking he just wanted to set the parameter. Seeing his updated comment, the script @Paul submitted is a better answer. – RyanDalton Jul 12 '13 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.