2

I need to import multiple ShapeFiles in ArcMap whith the MakeFeatureLayer tool. To do so, I need to rename several layers which contain non-ascii characters ("à","é","è", ...), space (" ") or point (".") in their names.

To be more precise, the issue appears when there is a point in the Shapefile name! The special characters appear to be accepted.

I already saw these posts:

MY "RAW" FILES

enter image description here

But, when I'm running my code, I got these errors in my IDE...

CODE

import os
import arcpy
from arcpy import env

folder = r'\TESTRENAME'
arcpy.env.workspace = folder

lfc = arcpy.ListFeatureClasses()

for f in os.listdir(folder):
    for fc in lfc:
        file_name, file_ext = os.path.splitext(fc)
        in_data = fc
        out_data = file_name.replace(".","_")+file_ext
        data_type = "ShapeFile"
        if in_data != out_data:
            arcpy.Rename_management(in_data, out_data)
        print out_data

ERRORS (IDE)

Traceback (most recent call last):
  File "<module1>", line 19, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 4507, in Rename
   raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Data Element: Dataset shp_19.2_160m.shp does not exist or is not supported
ERROR 000725: Output Data Element: Dataset C:\TESTRENAME\shp_19_2_160m.shp already exists.
Failed to execute (Rename).

ERROR (ArcMap)

enter image description here

As you can see, only the file with the extension ".shp" is renamed and not its related files which are added in ArcCatalog (and should not).

The result is then logically:

enter image description here

  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Question and Answer format. Please edit your question to include some information about the files you are trying to rename - What are they called, and what are you trying to rename them to? Can you include a screenshot from Explorer showing the files before you attempt any rename? – Midavalo Feb 10 '17 at 15:10
1

You're trying to split an arcpy object using the os module. You are only renaming the .shp extention of the component file. You are not renaming the shapefile, and all its components.

There's an easier way to rename feature classes or shapefiles using the arcpy.Describe function. See more information here.

Try this:

import os
import arcpy
from arcpy import env

folder = r'\TESTRENAME'
arcpy.env.workspace = folder

lfc = arcpy.ListFeatureClasses()

for fc in lfc:
    desc = arcpy.Describe(fc)
    newname = desc.baseName.replace(".", "_")
    arcpy.Rename_management(fc, newname)

Or another way is to just use the replace function directly, so:

for fc in lfc:
    arcpy.Rename_management(fc, fc.replace(".", "_"))
  • I already try this. The result is the same in ArcMap, but the error is different: IOError: "shp_P19.2_160m.shp" does not exist – tantmieux Feb 10 '17 at 10:00
  • Can you add the error here please – MacroZED Feb 10 '17 at 10:01
  • My bad, the code works without error. But the result is still the same in ArcMap: the ".shp" file is renamed, but not its related ".prj" and ".dbf" which are added in ArcCatalog as in the image above. So, ArcMap can't open it. – tantmieux Feb 10 '17 at 10:14
  • 1
    I don't think ArcGIS recognizes the something.*something*.shp as a shapefile, since the specification requires "8.3" naming. You can trivially wrap a list of os module rename function invocations to un-break this corrupt source. – Vince Feb 10 '17 at 12:01
  • I see the OP is using Rename_management(), which will rename all of the shapefile component files. os is used only for string manipulation, which is ok in this situation. – Aaron Feb 10 '17 at 15:24

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.