1

Need to go through multi shp file in a folder and copy a single feature which has the same name as entry to the new folder with staying same name and format. I create a piece of python code that can go through each shp file and also can to the output folder but, I can’t get any output. Any suggestion or concern please.

import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
Match_FC='Feature_Compare_01'
env.workspace =r'C:\Users\OutputTool\LineData\Separated Parcels'
output=r'C:\Users\Desktop\New Folder'
fcList = arcpy.ListFeatureClasses()

# Copy shapefiles to N folder-After looking with -9 characters 
for fc in fcList:
  if fc[-9:]==Match_FC:
    arcpy.FeatureClassToFeatureClass_conversion(fc, output,'{}_new'.format(fc))
1

Try placing two lines of code at the beginning of your for loop to make sure that you are getting the values that you think you are.

for fc in fcList:
  print fc
  print fc[-9:]
  if fc[-9:]==Match_FC:
    arcpy.FeatureClassToFeatureClass_conversion(fc, output,'{}_new'.format(fc))

Also, somewhere during Python 2.x, and ArcPy 10.x used several dot releases of Python 2.x, the syntax for '{}_new'.format() became available. Prior to that you had to explicitly number the tokens i.e. '{0}_new'.format() will work at more versions.

  • Thanks for your comments. I used print function and the result was including ".shp" and I added [-13:-3] to the script then work as i wanted, but there is a problem. It look like doesn't stop after it find the related shp file and running the scripts for long time. could you please let me know how can I add break to stop after the script find the related shp file with correct name and copy it to the folder. Thx – Koush Mar 17 '16 at 1:58
  • @Koush That sounds like a different question. I recommend seeing if you can solve it first, and if not, then see if you can create a test snippet that demonstrates just that problem to present as a new question. – PolyGeo Mar 17 '16 at 2:24
  • I added a break command after copy and creating FC and it works great. Thx – Koush Mar 17 '16 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.