AnsweredAssumed Answered

Delete Files in non-Workspace folder

Question asked by rralbritton1981 on Nov 7, 2012
Latest reply on Nov 7, 2012 by rralbritton1981
I have written a script to batch clip files within a workspace folder and save the files to a new output folder. Once this is done I would like to loop through all the records in the output files and delete any shapefile that has zero records (once the records are clipped they may contain zero files and therefore aren't necessary for further analysis). However, in order to create a list of shapefiles the ListFeatureClassess only seems to work for the defined workspace location. I've tried using the os.listdir as an alternative but it doesn't seem to work (script below). I'm thinking that I may need to save the batch clip files to the workspace directory, run the count and delete scripts and then write a script to move the clipped files to a new output folder, but would this be the only solution or is there a way to accomplish what I want?  - Thanks!

import arcpy,os arcpy.env.workspace = "C:/Project/ToolData" arcpy.env.overwriteOutput = True  outputWorkspace = "C:/Project/OutputData"  #Batch clip files in workspace and save to new output folder fcs = arcpy.ListFeatureClasses() clipper = someFile  try:     for fc in fcs:         clipped = outputWorkspace+"/"+fc[:-4]+"_clip.shp"          arcpy.Clip_analysis(fc,clipper,clipped)     except:     print arcpy.GetMessages(),'\n'  #Delete shapefile that have zero records files = os.listdir(outputWorkspace)  for file in files:     if file.endswith(".shp"):         outputCount = int(arcpy.GetCount_management(file).getOutput(0))         if outputCount ==0:             arcpy.Delete_management(file)