Skip to main content
Question

get directory-name as new filename / loop through subdirectories


vki
Contributor
Forum|alt.badge.img+7
  • Contributor
I have a directory with several subdirectories and four tif-files in each of them. The 4 tif-files have to be merged and the name of the new file has to be the name of the subdirectory.tif.

 

All those new files have to be output to the same, new directory.

 

 

So my problems are (I tried different things without success):

 

- how do I get the names of the subdirectories, so that I could use them as the new filenames?

 

- how do I loop through those subdirectories? (I guess I could use a workspace-runner, but then I would have to get the names of the subdirectories first > could this be done with the Schema-Reader...?)

 

 

Thanks in advance

 

Vera

 

 

3 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • April 13, 2015
I would use the Directory and File Pathnames reader.  You should end up with one feature per sub directory.  Use a StringConcatenator to build the path to the tif files @value(path_windows)\\*.tif, followed by a FeatureReader with the Dataset set to the attribute you just created.

 

Mosaic your tifs with a group-by on path_rootname  and use the same as a fanout on the tif writer.

takashi
Evangelist
  • April 14, 2015
Hi Vera,

 

 

Basically same as JDH's approach, but I would use the FilenamePartExtractor transformer to extract subdirectory name.

 

(1) Select the root directory for the Dataset of the TIFF Reader using the Advanced Browser, so that the reader reads every tiff file in the root/subdirectories.

 

(2) Expose "fme_dataset" in the TIFF Reader Feature Type Properties dialog > Format Attributes tab page. The "fme_dataset" will store full path of each tiff file.

 

(3) Add a FilenamePartExtractor and set "fme_datset" to the "Source Filename" parameter. The Folder Name Attribute (named "_dirname" by default) will be added to the feature, which stores the subdirectory name.

 

(4) Add a RasterMosaicker and set "_dirname" to the "Group By" parameter.

 

(5) Use "_dirname"  as the Fanout Attribute for the TIFF Writer Feature Type, so that the resulting tiff file name will be the "_dirname" (subdirectory name).

 

 

Takashi

vki
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • April 16, 2015
Takashi,

 

thanks a lot for your detailled answer. It works perfectly! 

 

(To get all the resulting files into the same directory, I had to set the fanout dataset parameter for the writer (navigator: advanced > parameter) to "no")

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings