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:
- How can I rename multiple feature classes (each different name) using Python?
- Multiple rename shapefiles and feature classes in python
MY "RAW" FILES
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)
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: