I have 100 shapefiles that share the same initial 44 characters. I would like to remove those initial identical 44 characters. The unique portion of the shapefile is the line number, i.e. Line_1006_1007. I want to rename the shapefile with the line numbers. Additionally, I want to remove the .kml before the .shp in the name. Here are three examples of the shapefile name below.




I am using ArcGIS 10.4 with all of the extensions available.

closed as off-topic by BERA, radouxju, John Powell, ahmadhanb, PolyGeo Jul 14 '17 at 8:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – BERA, radouxju, John Powell, ahmadhanb, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


I'd use Rename_management (in_data, out_data, {data_type}) (in arcpy) This would be an easy script to write and I think the best way to do this. In Python you can use the strip() function.

So you'd write a loop using something like arcpy.ListFeatureClasses() and within that loop you can use something like out_data = in_data.strip("annoying44charstring...") on each "item" within your loop.

The python method provided by @BERA would work well as long as you don't have other files that might be affected though if they had the same 44 character string that might be OK to rename those too (depends on what you want it to do).


As BERA already mentioned, you should ideally use Python for this. Look at the link provided above and start from there.

To start with, I'd recommend the following workflow:

  1. Set the workspace to the folder containing the shapefiles you want to process
  2. List all your shapefiles in the workspace
  3. Iterate through the listed shapefiles and:

    • Read out their file names (cut the path, i.e. using the os.path.split() function, see this link for more details)

    • cut the left 44 characters and the right 8 characters (including the points) from the file name (using something like newfileName = filename[44:-8] which returns a string from position 45 (0 being the first position) excluding the last 8; see this link for more details)

    • copy the feature class (i.e. using arcpy.FeatureClassToFeautreClass_conversion() being iterated using the newfileName (together with the desired output path) as the outputfile

  4. Optionally delete all the original shapefiles in the list


Don't feel comfortable with the programming, her's an old DOS trick.

open cmd prompt, cd to the folder where your hundred shapefiles are.

dir *.shp /b >files.txt

now you have a listing of all your shapefiles. Open this txt file in excel. Note the file names are in A, so right click on A, select insert, and type in 'rename" drag this to the end of your records.

Now copy the B column to C. Now in the C do a find replace on 'Lines_P_10345_-_600_Mile_Project_Collection_' with ''(nothing) it should remove the extra leading part of the file name you don't want. Now do another find/replace with the '.KML' to remove it. Lastly on the B and C columns do one last find/replace 'shp' to '*'

Now save it. quit excel. I did this with some of my file as an example, when you open the text file you should see something like this:

rename MCParcels.* oldMCParcel.* rename mercerCo.* oldmercerCo.* with your file names.

Now the fun part rename file.txt to files.bat, use the cmd prompt to do this so you don't get files.txt.bat, you want files.bat.

Now in the CMD prompt just type files.bat and hit enter, it will rename them and all the associated files. You can also just double click on the file.bat and it will run.

This trick takes a few minutes to setup but I've renamed 1500 jpgs in a few seconds.


If you have R, you could copy and paste this code into R. It should do exactly what you want.

###Set your working directory to wherever you are keeping your files####

temp = list.files(pattern="*.kml.shp")
####This will delete all the text up to and including the word 'Line_'####
for(x in 1:length(temp)) {
variablea = gsub(".*Line_","",temp[x])
####This will replace .kml.shp with .shp#####

for(x in 1:length(myvar)) {
evennewerfilename = gsub(".kml.shp",".shp",myvar[x])

This code will only rename the .shp files. To rename your .prj, and.dbf files, you will need to run lines 1-9 again, but change the pattern from *.kml.shp to the respective file extension you want to change.

  • I've tested my code with your file names. It works. – J.W. Powell Jun 30 '17 at 18:11
  • It will loop through all hundred files in about five seconds. – J.W. Powell Jun 30 '17 at 18:12
  • You can download R here: cloud.r-project.org Once you download it, all you need to do it open it, copy the code I wrote, change the working directory to where your files are stored, and paste it into the console. – J.W. Powell Jun 30 '17 at 19:02
  • 1
    No, this code will only rename the actual .shp file, the .dbf and such will retain the old name, rendering the dataset broken/unusable! – til_b Jun 30 '17 at 20:47
  • Oh, good point @til_b! If Ash has even a little coding experience they can modify the code to rename the .dbf, .prj etc. as well. The only part of the code that would require changing is the pattern in line 4. They wouldn't need to use the second half of the code (lines 10-16) for anything other than the actual .shp file. – J.W. Powell Jun 30 '17 at 20:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.