I am trying to write a python script to walk through all folders in my workspace and find and compact all geodatabases in my workspace. I am using the 10.2.2 release.
import acrpy, os
from arcpy import env
arcpy.env.workspace "C:"
for (path, dirs, files) in os.walk(arcpy.env.workspace)
for file in files if ".gdb" in file:
workspaces = arcpy.ListWorkspaces("*", "FileGDB")
for workspace in workspaces:
arcpy.Compact_management(workspace)
Solved! Go to Solution.
Hi Jason,
You can use the arcpy.da.Walk function to walk through the directories and then compact each geodatabase. Here is an example:
import arcpy, os workspace = r"C:\temp\python" for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, datatype="Container"): for dirname in dirnames: if ".gdb" in dirname: arcpy.Compact_management(os.path.join(dirpath, dirname)) print "Successfully compacted " + dirname
Hi Jason,
You can use the arcpy.da.Walk function to walk through the directories and then compact each geodatabase. Here is an example:
import arcpy, os workspace = r"C:\temp\python" for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, datatype="Container"): for dirname in dirnames: if ".gdb" in dirname: arcpy.Compact_management(os.path.join(dirpath, dirname)) print "Successfully compacted " + dirname
Works great, I did finally get the other method working but this is much better than what I was trying to do. Much appreciated!