Rename a list of SHP files in Python

09-08-2015 06:32 AM
New Contributor II

Hello people,

I have a list of SHP files that I want to rename. First, I want to replace the "." from the shp to "_", and then rename the file. As you can see in the image below:

This the code that I am using:

import arcpy, os


for filename in arcpy.ListFeatureClasses():


    a=filename.replace('.', '_')


    arcpy.Rename_management(filename, a)


    print "ok"

The problem is that when I am trying to open the SHP file it does not work. I am getting the following error message:

Does anyone knows how to fix the problem...

Thanks for your help

0 Kudos
11 Replies
New Contributor II

The code seems to work... it does not give any error message in PyScripter...But when I am trying to add the shp to ArcMAP it gives the following error:

0 Kudos
Regular Contributor III

Your trying to hard

import arcpy

arcpy.env.worcspace = "Your workspace"

for file in arcpy.ListFeatureClasses():

  a = "shp_" + file.replace('.','_')