Say I have 40 database connections in a folder, is there some way to just export every database that has a connection?
Instead of writing
in_data = "c:/data/StJohns.gdb"
out_file = "c:/data/StJohns.xml"
export_option = "SCHEMA_ONLY"
storage_type = "BINARY"
export_metadata = "METADATA"
# Execute ExportXMLWorkspaceDocument
arcpy.ExportXMLWorkspaceDocument_management(in_data, out_file, export_option, storage_type, export_metadata)
40 times?
A simple model should suffice as shown below:
Use the Iterate Workspace to return File GeoDatabases and tick on recursive if you want drill down into the sub-folders. You would then use inline substitution to ensure a unique file name for the Output file.
If you want to do this in just python then look at this function here.
I'd like to do it with Python. The Python function you listed is shown working for arcpy.Compact_management which would get the its "in_workspace" from
workspaces = arcpy.ListWorkspaces("*", "FileGDB")
but arcpy.ExportXMLWorkspaceDocument_management requires a "out_file" variable, so how would that work with workspaces = arcpy.ListWorkspaces("*", "FileGDB")?
Hi Michael,
Try this:
import arcpy, os
arcpy.env.workspace = r"<path>"
workspaces = arcpy.ListWorkspaces("*", "FileGDB")
for workspace in workspaces:
print workspace
n,t = os.path.basename(workspace).split(".")
xml = arcpy.env.workspace + os.sep + "{0}.xml"
arcpy.ExportXMLWorkspaceDocument_management(workspace, xml.format(n))
Is my path formatting incorrect?
I've tried
arcpy.env.workspace = r"D:/Valor/"
and the script bales pretty quick, don't even see a error message.
If you use r before the string, use the regular Windows backslash in your path - \. Using a forward slash is for when you don't use r. Using it the way you have above, python interprets the forward slash as just that, a forward slash, which does not work on Windows.
Windows 7 machine.
I've tried
None of them work. The black box opens up quickly with no error message before closing. Nothing happens
Instead of setting the workspace, try just putting the path there. In another thread. Richard Fairhurst stated that setting the env environment settings in a stand-alone script didn't actually do anything.
Where are you attempting to run the script? In an IDE like IDLE or PyScripter? Or directly in the python window in ArcMap?
If you want to run the script in the Command Prompt you will have to change directories to the location of the script and call it:
I would recommend running the script in an IDE...I like PyScripter but some people like IDLE or PythonWin.
Running the script by just double-clicking on it from its Windows folder.