๐ผ️ Batch Filename Extraction for Photo Fields Across Multiple GDBs (ArcPy)
In many GIS workflows, feature classes often store file paths to images or documents—such as photos captured in the field. However, storing the full file path may not always be ideal. Sometimes you only need the filename (e.g., for linking, display, or standardization purposes).
This ArcPy script automates the process of extracting filenames from path strings for specified fields across multiple File Geodatabases (GDBs). It's a powerful way to clean and standardize your photo field data with minimal manual effort.
๐ How the Script Works
๐ Directory Setup
The script starts by defining the folder containing all your GDBs. It automatically loops through each .gdb file inside that folder.
๐งพ Fields & Expressions
You define a list of fields to update (Photo, Photo1, Photo2, etc.) and a corresponding list of Python expressions that extract just the filename from each path using:
This expression splits the full file path by double backslashes (\\) and retrieves the last part (i.e., the filename).
๐ GDB Traversal
The script processes:
-
Standalone feature classes
-
Feature classes inside datasets
Each feature class is scanned, and if the field exists, it gets updated using arcpy.management.CalculateField() with the specified Python expression.
๐ก️ Smart Checks
If a field doesn’t exist in a feature class, the script skips it gracefully with a message.
๐ง The Code
๐ก Use Case Scenarios
-
Removing long or broken directory paths from image/document fields
-
Extracting filenames for linking in web maps or reporting systems
-
Normalizing photo fields across merged or imported datasets
-
Automating repetitive clean-up tasks across dozens of GDBs
✅ Key Benefits
-
Works seamlessly across multiple geodatabases
-
Applies to both standalone and nested feature classes
-
Uses Python 3 expressions, ensuring compatibility with ArcGIS Pro
-
Gracefully skips missing fields to avoid errors