0

I am trying to write a python script that would allow me to download data and copy it to a file geodatabase. The script currently downloads and extracts a zip folder from a FTP site. Ideally I would like my script to then copy the extracted shapefile into a geodatabase. The workspace in which the data is extracted remains constant. Where as the name of the data that is downloaded and extracted is variable. How can I reference the downloaded data regardless of its name for the input argument of the CopyFeature tool?

arcpy.env.workspace = r'C:\Users\Desktop\ExtractedData'
arcpy.CopyFeatures_management( downloaded shapefile, 'C:\Users\Desktop\Test.gdb')
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 14, 2015 at 22:14

2 Answers 2

2

If you know the folder use ListFeatureClasses to get a list of the feature classes in your workspace:

import os, arcpy
arcpy.env.workspace = r'C:\Users\Desktop\ExtractedData'
for ThisFC in arcpy.ListFeatureClasses():
 GDBName,Ext = os.path.splitext(ThisFC) # splits out name and extension
 GDBName = GDBName.replace(" ","_") # get rid of spaces in shapefile names
 arcpy.CopyFeatures_management( ThisFC, r'C:\Users\Desktop\Test.gdb' + GDBName)
answered Sep 14, 2015 at 22:26
2
  • An ancillary goal for my script is to incorporate it into an arcgis toolbox. Would you have any suggestions as how I could set the output for the copy feature tool to a multivalue - GetParameterAsText? So I can copy the data to multiple geodatabases? Commented Sep 14, 2015 at 22:59
  • I always use sys.argv[] to get the parameters, but an output is slightly different.. I think you need to Get the parameter as normal then use SetParameterAsText to enforce it at the end of the script, have a read of help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… about input/output parameters. Commented Sep 14, 2015 at 23:13
2

I think you should look at the first ListFeatureClasses example in the online help for arcpy.ListFeatureClasses() for ideas on how to incorporate that function.

It has example code to:

Copy shapefiles to a geodatabase

i.e. very similar to what you are trying to do in the code snippet that you have presented.

answered Sep 14, 2015 at 22:25
1
  • 1
    Beat me by one minute PolyGeo. At least the answers are consistent. Commented Sep 14, 2015 at 22:28

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.