Question

How do I batch rename several shape files based on their parent folder name and/or write that folder name into the file as a new attribute?

  • 6 May 2021
  • 1 reply
  • 10 views

Hi

I've tried following the recipe in this article https://community.safe.com/s/article/Using-the-Directory-and-File-Pathnames-Reader-Record-File-Metadata for reading metadata on a bunch of shape files stored in different subfolders (one *.shp per folder) in parent folders in a collective project directory.

All the shape files (54 in total) have the same file name "Vejle.shp" with similar attributes in them. So I only have the distinct [parent-folder/subfolder] names to identify them from another. My goal is to use the the outcome metadata for renaming all the shapefiles so they are matching the folder names.

Or even better: directly write a new attribute to the files based on the respective input folder name as i transform and load my data from shape into one feature class in an ESRI file geodatabase.

How do I do that?


1 reply

Userlevel 2
Badge +17

Hi @thard

The Directory and File Pathname reader method used in the article you linked would be suitable for renaming the file if used in combination with the File Copy writer.

For getting the distinct parent folder/subfolder value, you can use two consecutive FilenamePartExtractor--one to get the subfolder and the other to get parent directory from the path_windows attribute. Alteratively, you can also use a StringSearcher if you are familiar with Regex to get parent folder/subfolder.

If you wish to add a new attribute to the shapefiles, then you will need to use the Shapefile reader to read the shapefiles. Expose the fme_dataset format attribute and use either the FilenamePartExtractor or StringSearcher.

Reply