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 Answer 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. ThxKoush– Koush2016年03月17日 01:58:28 +00:00Commented 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.2016年03月17日 02:24:05 +00:00Commented Mar 17, 2016 at 2:24
-
I added a break command after copy and creating FC and it works great. ThxKoush– Koush2016年03月17日 03:50:23 +00:00Commented Mar 17, 2016 at 3:50