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.

  • Please always provide error messages as text rather than pictures so that they are available for future searches. – PolyGeo Feb 2 '18 at 0:51
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) 

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.