I've been tasked with renaming a large amount of raster files within a file geodatabase (ArcGIS style).

I'm taking weather data which has a name format as such: "G"mmddhhhh I'm trying to add a year tag in between the G and month: "G"yyyymmddhhhh

Here is the function that I've written:

# ----------------------------------------------------------------------------- #
def renameRasters(FGDB):
    origdir = arcpy.env.workspace
    arcpy.env.workspace = FGDB

    for rstr in arcpy.ListRasters("G*"):
            newrstr = "G" + "2014" + rstr.replace("g", "")
            arcpy.Rename_management(rstr, newrstr)

            print "Failed to rename: " + rstr

    arcpy.env.workspace = origdir
    return None
# ----------------------------------------------------------------------------- #

This function works fine for a small to medium amount of rasters within a FGDB and takes about 1.5 seconds per raster renamed. I run into issues when there are a large number of files to be renamed. 1,200 files takes > 10 hours. At the same rate as the smaller raster sets this should take < 1 hour...

Does anyone have an idea on how to make this process go faster?

If not I'll set it up to run over the weekend.

I should mention that I am using ArcGIS 10.2.2.

  • I wonder if instead of using arcpy if it would be more efficient to modify the actual folder/file names with os.walk ? – GISKid Aug 20 '14 at 17:40
  • What specific issues are you running into on larger FGDBs? Is the FGDB on a local filesystem or on a networked one? Have you tried putting a delay ( time.sleep(0.5) ) into the loop to prevent race conditions? (Please update the question) – Vince Aug 20 '14 at 17:43
  • possible duplicate of ArcPy Rename Loop – radouxju Aug 20 '14 at 18:26
  • 3
    os.walk will not work on FGDBs. Instead, if you have at least ArcGIS 10.1 service pack 1, you could try using arcpy.da.Walk. It might be faster. Very large lists in python can be memory intensive. – Fezter Aug 21 '14 at 0:37
  • 2
    @Fezter, a list of 1200 files in a FGDB won't be very memory intensive. I've used ListRaster() over a parent directory containing ~100 folders and ~30k images, and it completed in a few minutes. Listing the images probably isn't the bottleneck. – Paul Aug 21 '14 at 2:25

I have used Rename Master a lot for similar sounding tasks with much success.

It will add, replace or remove all or part of the filename, employ filters so only specific files within the selected folder are displayed, and preview all changes before you click the rename button.

2017 Techworld.com article on it here screen shot

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 6
    I do not believe this supports ESRI FGDB format. – Aaron Aug 20 '14 at 19:50

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.