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))
asked Mar 17, 2016 at 1:16

1 Answer 1

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.

answered Mar 17, 2016 at 1:42
3
  • 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 Commented Mar 17, 2016 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. Commented Mar 17, 2016 at 2:24
  • I added a break command after copy and creating FC and it works great. Thx Commented Mar 17, 2016 at 3:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.