Bulk delete the GIS database empty layer.
#-*-coding:utf-8-*-# ---------------------------------------------------------------------------#merge.py#Created on:2013-01-21 10:25:22.00000#(generated by wanglin_tjch)#Description:# ---------------------------------------------------------------------------#Import arcpy ModuleImportarcpyImportOs.pathImport TimeImportRandom fromarcpyImportEnvfcdbdir="d:\\aaa"DICALLFC={}fcall=[]gdballpath=[]if notisinstance (fcdbdir,unicode): Fcdbdir= Fcdbdir.decode ('Utf-8')#Get Dataset and Featureclass,store in Dicallfc,key =fc value= DSifos.path.exists (fcdbdir): forDirpath,dirnames,filenamesinchOs.walk (fcdbdir):#Traverse gdb folder to get GDB forDirNameinchDirnames:if ". GDB" inchDirname:gdbfilepath=Os.path.join (dirpath,dirname)if notGdbfilepathinchGDBAllPath:GDBAllPath.append (Gdbfilepath)#Iterate MDB folder get MDB forFileNameinchFilenames:ifOs.path.splitext (filename) [1]=='. mdb': Mdbfilepath=Os.path.join (dirpath,filename)if notMdbfilepathinchGDBAllPath:GDBAllPath.append (Mdbfilepath)#Traverse shp folder to get shape forFileNameinchFilenames:ifOs.path.splitext (filename) [1]=='. SHP': Shpfilepath=Os.path.join (dirpath,filename)if notDirpathinchGDBAllPath:GDBAllPath.append (Dirpath) forEveryfilepathinchGDBAllPath:env.workspace=Everyfilepath singlefclist= arcpy. Listfeatureclasses (""," All") ifSinglefclist andLen (singlefclist) >0: forSinglefcinchsinglefclist:#if SINGLEFC is Unicode then do not change, otherwise utf-8 SINGLEFC encoding is decoded to Unicode if notisinstance (singlefc,unicode): SINGLEFC= Singlefc.decode ('Utf-8') ifisinstance (everyfilepath,unicode): Fcfullpath= everyfilepath+"\\"+SINGLEFCElse: Fcfullpath= everyfilepath+"\\"+singlefc.encode ('gb2312') Rows= arcpy. Searchcursor (Fcfullpath,"","","","") Count=0 forFeaturecountinchRows:count=count+1ifCount = =0:arcpy. Delete_management (Fcfullpath)Print "Delete"+fcfullpath+"succeed at"+time.strftime ("%y-%m-%d%x", Time.localtime ()) Datasetlist= arcpy. Listdatasets ("","Feature") forDataSetinchdatasetlist:#If the dataset is Unicode, it does not change, otherwise the Utf-8 dataset encoding is decoded to Unicode ifisinstance (dataset,unicode): DataSet=DataSetElse: DataSet= Dataset.decode ('Utf-8') ifisinstance (everyfilepath,unicode): Env.workspace= everyfilepath+"\\"+DataSet Dspath= everyfilepath+"\\"+DataSetElse: Env.workspace= everyfilepath+"\\"+dataset.encode ('gb2312') Dspath= everyfilepath+"\\"+dataset.encode ('gb2312') Fclist= arcpy. Listfeatureclasses ("") ifFclist andLen (fclist) >0: forFcinchfclist:#If FC is Unicode then do not change, otherwise Utf-8 FC encoding is decoded to Unicode ifisinstance (fc,unicode): FC=FCElse: FC= Fc.decode ('Utf-8') ifisinstance (dspath,unicode): Fcfullpath= dspath+"\\"+FCElse: Fcfullpath= dspath+"\\"+fc.encode ('gb2312') Randomviewname= fc+"View"+str (Random.randint (1,100000) arcpy. Maketableview_management (fc,randomviewname) Count=0 Count=Int (arcpy. Getcount_management (Randomviewname). GetOutput (0))ifCount = =0:arcpy. Delete_management (Fcfullpath)Print "Delete"+fcfullpath+"succeed at"+time.strftime ("%y-%m-%d%x", Time.localtime ())Else: Print "Dir not Exist"Print " Done"
View Code
Delete a GIS database empty layer (Gdb,mdb,shape)