1

I'm trying to run a script tool in Arcmap that will reproject a number of shapefiles from the source data folder and place the newly projected shapefiles in a destination data folder.

I'm getting the following error 000732 with my arcpy script:

enter image description here

Here is my script (the error is coming from the final line):

import arcpy, os 
from arcpy import env 
source_data_folder = arcpy.GetParameterAsText(0)
out_coordinate_system = arcpy.GetParameterAsText(1)
destination_data_folder = arcpy.GetParameterAsText(2)
for (path, dirs, files) in os.walk(source_data_folder): 
 for file in files: 
 # find all .shp files in folder and all subfolders 
 if ".shp" in file.lower()[-4:]:
 outpath = os.path.join(destination_data_folder, file)
 arcpy.Project_management(file, outpath, out_coordinate_system) 

The shapefile that the error is referring to ("Class_NS.shp") is the first shapefile in the "source_data_folder". So the script is running that far - it's finding the first shapefile, it's just claiming it "does not exist or is not supported".

The shapefile most definitely exists.

Does this mean it is not supported?

It's just a regular shapefile.

There may be errors with my code but so far the error message is not code-related.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 14, 2017 at 1:25
1
  • Please always provide error messages as text rather than pictures so that they are available for future searches. Commented Feb 2, 2018 at 0:51

1 Answer 1

8

You just need to include the root path with the shapefile "file" name. os.walk returns the root and then either the directory or file for every element in each folder - meaning that for each file variable in the loop, the name is only "somefile.shp" without any path information, which arcpy needs to process. So an additional line will get this to work as intended:

import arcpy, os 
from arcpy import env 
source_data_folder = arcpy.GetParameterAsText(0)
out_coordinate_system = arcpy.GetParameterAsText(1)
destination_data_folder = arcpy.GetParameterAsText(2)
for (path, dirs, files) in os.walk(source_data_folder): 
 for file in files: 
 # find all .shp files in folder and all subfolders 
 if ".shp" in file.lower()[-4:]:
 input_shp = os.path.join(path, file)
 outpath = os.path.join(destination_data_folder, file)
 arcpy.Project_management(input_shp, outpath, out_coordinate_system) 
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Nov 14, 2017 at 1:29
1
  • 3
    Consider using arcpy.da.Walk (source_data_folder, datatype=''FeatureClass") resources.arcgis.com/en/help/main/10.2/index.html#//…, that way you only get the Esri recognized feature classes and rasters, also fName,fExt = os.path.splitext(file) then if fExt.lower() == '.shp': to find only the shapefiles. Commented Nov 14, 2017 at 1:41

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.