HowTo:  Automate deleting of objects owned by a schema

相关信息
Article ID: 40919
Software:
ArcGIS - ArcEditor 10
ArcGIS for Desktop Advanced 10.1
ArcGIS for Desktop Standard 10.1
Platforms:
Windows XP, Server 2003, Server 2008, Windows 7, Windows 8

问题描述
GIS managers and administrators sometimes need to delete all feature datasets, feature classes and tables from a database owned by a particular schema.
已邀请:

EsriSupport

赞同来自:

解决方案
The below Python script provides an automated way of deleting feature datasets, feature classes and tables from a database owned by a particular schema.
  1. Modify the variables below according to the environment. The variables are located below main statement:
    logWorkspace = "C:/Temp" workspace = "C:/connections/LOCATOR_CONN/DATAOWNER.sde" dLogName = "Log_dataset_del.txt" fLogName = "Log_fc_del.txt" tLogName = "Log_table_del.txt" schema = "sde.DATAOWNER" 
    schema=DATAOWNER is case-sensitive: 
    • Oracle: DATAOWNER • SQL Server: db_name.DATAOWNER • PostgreSQL: db_name.DATAOWNER
  2. import arcpy, os, stringdef DelDatasets(logWorkspace,dLogName,workspace,schema):    logfile = open(os.path.join(logWorkspace, dLogName), 'w')    arcpy.env.workspace = workspace    datasetList = arcpy.ListDatasets()    for dataset in datasetList:        if dataset.startswith(schema):                        arcpy.Delete_management(dataset)            print ("Deleted Feature dataset {0}".format(dataset))            logfile.write("Deleted Feature dataset {0}".format(dataset))            logfile.write("\n")    logfile.close()    del logfile, datasetList    def DelFeatureClasses(logWorkspace,fLogName,workspace,schema):    logfile = open(os.path.join(logWorkspace, fLogName), 'w')    arcpy.env.workspace = workspace    fcList = arcpy.ListFeatureClasses()    for fc in fcList:        if fc.startswith(schema):                        arcpy.Delete_management(fc)            print ("Deleted feature class {0}".format(fc))            logfile.write("Deleted feature class {0}".format(fc))            logfile.write("\n")    logfile.close()    del logfile, fcListdef DelTables(logWorkspace,tLogName,workspace,schema):    logfile = open(os.path.join(logWorkspace, tLogName), 'w')    arcpy.env.workspace = workspace    tableList = arcpy.ListTables()    for table in tableList:        if table.startswith(schema):                        arcpy.Delete_management(table)            print ("Deleted table {0}".format(table))            logfile.write("Deleted table {0}".format(table))            logfile.write("\n")    logfile.close()    del logfile, tableList    if __name__ == "__main__":        logWorkspace = "C:/Temp"    workspace = "C:/connections/LOCATOR_CONN/DATAOWNER.sde"    dLogName = "Log_dataset_del.txt"    fLogName = "Log_fc_del.txt"    tLogName = "Log_table_del.txt"    schema = "sde.DATAOWNER"    DelDatasets(logWorkspace,dLogName,workspace,schema)    DelFeatureClasses(logWorkspace,fLogName,workspace,schema)    DelTables(logWorkspace,tLogName,workspace,schema)   


创建及修改时间
Created: 3/8/2013

Last Modified: 8/6/2013
原文链接
http://support.esri.com/en/kno ... 40919

要回复问题请先登录注册