Tuesday, May 22, 2012

Compressing File Geodatabases in a Folder

In a previous post, I showed how to uncompress a set of file geodatabases in a folder.  To compress a set of file geodatabases, using the CompressFileGeodatabase_management().  This script will use the List functions to list all the file geodatabases and then compress them.  When completed successfully it returns 'true' else it returns false.

import arcpy
from arcpy import env
if __name__ == '__main__':
    try:
        workspace = arcpy.GetParameterAsText(0)
        env.workspace = workspace
        fgdbs = arcpy.ListWorkspaces("*","FileGDB")
        for fgdb in fgdbs:
            arcpy.CompressFileGeodatabaseData_management(fgdb)
        env.workspace = None
        arcpy.SetParameterAsText(1,True)
    except:
        env.workspace = None
        arcpy.AddError(str(arcpy.GetMessages(2)))
        arcpy.SetParameterAsText(1,False)

Enjoy