Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have approximately 1500 raster files following this format:


I need these subsetted to, for example: 3609922nw. What are appropriate methods to rename large numbers of spatial data, that may or may not contain ancillary files (e.g. .xml, .ovr)?

share|improve this question
Does it have to be ArcPy? If the filenames are that uniform, it is easy to create a batch file that does what you want using a combination of Excel and a text editor. Otherwise, with moderate difficulty (no more that ArcPy) you could write a batch file that uses regex to rename the files. – user3461 Jun 13 '12 at 19:31
up vote 11 down vote accepted

Something like this ought to get you going...

import os
import arcpy
from arcpy import env

# directory containing rasters to be renamed
RASTER_DIR = 'C:/MyRasters/'

env.workspace = RASTER_DIR
for raster in arcpy.ListRasters():

    # get the raster name and file extension
    fileName,fileExtension = os.path.splitext(raster)

    # do some shenanigans to rename the file
    # based on your sample raster name, fileNameParts would look like
    # fileNameParts[0] = m
    # fileNameParts[1] = 3609922
    # fileNameParts[2] = nw
    # fileNameParts[3] = 14
    # fileNameParts[4] = 1
    # fileNameParts[5] = 20100425

    fileNameParts = fileName.split('_')
    compactFileName = fileNameParts[1] + fileNameParts[2] + fileExtension

share|improve this answer

protected by whuber Jul 20 '12 at 12:46

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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