1

I'm trying to create a folder and export the following shape files to the new folder. I got it to create the folder but I can't seem to get the shapefiles to the new folder.

import arcpy
import datetime
from arcpy import env

env.workspace = "C:/UPDM.gdb"
out_folder_path = "C:/output"
nowstart = datetime.datetime.now()
YearMonthDay = nowstart.strftime("%Y_%m_%d")
out_name = "WebTMS_BU_" + YearMonthDay + ""

arcpy.CreateFolder_management(out_folder_path, out_name)

arcpy.FeatureClassToShapefile_conversion(["P_Leaks"],
                                         out_name)

2 Answers 2

3

You need to reference the full output folder path in your FeatureClassToShapefile_conversion call. Currently you are passing your out_name variable which only represents the string "WebTMS_BU_" + YearMonthDay + "". So make this change:

arcpy.FeatureClassToShapefile_conversion(["P_Leaks"],
                                         os.path.join(out_folder_path,out_name)

And you will need to add the os module:

import os
0

To add to the answer above, another way is to use Arcpy.getOutput method. In this way, you can set the output of the geoprocessing tool as a variable. For example:

result = arcpy.CreateFolder_management(out_folder_path, out_name)
new_folder = result.getOutput(0)

The variable "new_folder" can then be used going forward through your script when using ArcGIS geoprocessing.

arcpy.FeatureClassToShapefile_conversion(["P_Leaks"],
                                         new_folder)

However, this method wont work when using other python modules outside of Arc. The OS method mentioned above is a more full-proof python way of joining paths, but just wanted to mention the get.Output method which can be used to identify the outputs from most Arc geoprocessing functions.

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.