2

I have a Geodatabase full of featureclasses. I want to perform the following:

  1. Copy out each individual featureclass as an output individual shapefile (and have the same name).
  2. Create individual Output Folders (of the same output shapefile name).
  3. Copy each output shapefile into its own unique folder (of the same name).

Currently, I can perform task 1 and 2 above, however, I am having trouble with task 3 above. My results so far is that I can create the output shapefiles and folders (of the same name), however, the shapefile outputs do not sit in the pertaining folders. i.e. My result = a bunch of shapefiles and a bunch of folders. I need to (i) either have the shapefiles created and automatically placed into the pertaining folder (based on the same name of the shapefile), or (ii) After creating the shapefiles and folders, move or copy the output shapefiles into each pertaining folder (based on the same name as the shapefile).

Therefore, for each of my featureclasses, my end result would be 1 seperate folder housing 1 shapefile (same name for both folder and shapefile).

I am fairly new to Python.

Input vs Current Output vs INTENDED OUTPUT

# import system modules
import arcpy
import os
from arcpy import env
# Set environment settings
# Note: The INPUT Geodatabase below houses 5 x featureclasses
env.workspace = r"D:\INPUT.mdb" 
arcpy.env.overwrite = True
# Set local vairables
# Note: Ensure that you have this empty folder already created within FileManager etc.
outWorkspace = "D:/OutputFoldersAndSHP"
print "Commencing"
# Use the ListFeatureClasses function to generate a list of featureclasses in the env.workspace further above
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
 # PHASE 1: CREATE A FOLDER BASED ON INDIVIDUAL FC NAMES
 # Note: (It simply uses the fc name as the output folder name!) 
 arcpy.CreateFolder_management(outWorkspace, fc)
 # PHASE 2: COPY FEATURECLASSES TO SHAPEFILES
 # Determine the new output shp path and name
 outSHP = os.path.join(outWorkspace, fc)
 arcpy.CopyFeatures_management(fc, outSHP)
print "Completed"
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 22, 2016 at 3:33
1

2 Answers 2

2

You need to specify the output shapefile. So the last line should be

arcpy.CopyFeatures_management(fc, os.path.join(outSHP, fc + '.shp'))

That should create the directory structure you're looking for.

answered Nov 22, 2016 at 3:58
2
  • @Jim, I just tested this, and it works. You need to keep the create folder management section. Commented Nov 22, 2016 at 4:18
  • BINGO!!! FANTASTIC! THIS WORKED PERFECTLY... Commented Nov 22, 2016 at 4:19
1

Try this:

for fc in fcs:
 # PHASE 1: CREATE A FOLDER BASED ON INDIVIDUAL FC NAMES
 # Note: (It simply uses the fc name as the output folder name!) 
 outSHP = arcpy.CreateFolder_management(outWorkspace, fc)
 # PHASE 2: COPY FEATURECLASSES TO SHAPEFILES
 arcpy.CopyFeatures_management(fc, outSHP)
print "Completed"

I tested this and outSHP returns the path to the folder.

answered Nov 22, 2016 at 3:55
2
  • so does the outSHP = os.path.join(outWorkspace, fc) line though Commented Nov 22, 2016 at 4:03
  • Unfortunately, the 'Try this' response above still has folders and shp output (not shp within folder). Thank you so much for your quick reply and attempt. Your help was much appreciated though – thank you! Commented Nov 22, 2016 at 23:07

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.