Skip to main content
Question

How to select a folder within the folder path to use as an attribute


Hi,

I have used the FilenamePartExtractor many times with good results. It is very helpful to be able to pass the root folder of the data to other transformers. I have a similar requirement for a workspace, however in this example I wish to use the folder above the root folder as they attribute.

 

For example, if I am reading the Source data from this path

C:\\WINNT\\Profiles\\user\\Desktop\\roads.shpI wish to use the 'user' folder to fanout the Writer to create an output folder 'user'. I will then fanout by fme_basename to create the roads.shp within that 'user' folder.In this instance the FilenamePartExtractor does not work as it it does not cater for anything above the Folder Name/_dirname = 'Desktop'

 

Can someone help me out to extract the 'user' component of the file path so it can be used as an Attribute Value for Fanout?ThanksAndrew

8 replies

todd_davis
Influencer
Forum|alt.badge.img+22
  • Influencer
  • April 10, 2017

Well you can write a number of things to do it, but just use another FileNamePathExtractor after the first one and set the input attribute as _dirpath. Then you will get what you want out of the output


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • April 10, 2017

I would use the Directory and File Pathnames Reader and extract the infomation out of the path returned.


takashi
Influencer
  • May 2, 2017

Another possible approach: split the source file path with an AttributeSplitter (Delimiter: \\), then extract the third element from the last of the resulting list with a ListIndexcer (List Index: -3).


david_r
Evangelist
  • May 2, 2017
takashi wrote:

Another possible approach: split the source file path with an AttributeSplitter (Delimiter: \\), then extract the third element from the last of the resulting list with a ListIndexcer (List Index: -3).

Agreed, just be careful because it won't work on Linux or Mac.

takashi
Influencer
  • May 2, 2017
takashi wrote:

Another possible approach: split the source file path with an AttributeSplitter (Delimiter: \\), then extract the third element from the last of the resulting list with a ListIndexcer (List Index: -3).

Thanks for the point, @david_r.

 

If the workspace should be run on any platform including both Windows and UNIX, replace every backslash \\ with slash / beforehand, and then use the slash as delimiter in the AttributeSplitter.

 

Windows considers both backslash and slash as path delimiter, but UNIX only allows to use slash as path delimiter. I therefore prefer to use the slash, usually.

 


david_r
Evangelist
  • May 2, 2017
takashi wrote:
Thanks for the point, @david_r.

 

If the workspace should be run on any platform including both Windows and UNIX, replace every backslash \ with slash / beforehand, and then use the slash as delimiter in the AttributeSplitter.

 

Windows considers both backslash and slash as path delimiter, but UNIX only allows to use slash as path delimiter. I therefore prefer to use the slash, usually.

 

I agree, paths can be surprisingly complicated. Here's an example that I often see on FME Server instances:

 

D:/apps/FMEServerRepository///resources/logs/engine/current/jobs\1000\job_1128.log
Notice the mix of forward and backward slashes, as well as duplicate slashes =)

  • Author
  • May 22, 2017
todd_davis wrote:

Well you can write a number of things to do it, but just use another FileNamePathExtractor after the first one and set the input attribute as _dirpath. Then you will get what you want out of the output

Thanks Todd, your solution is simple and effective, I couldn't see at the time that this approach would work!

 


  • Author
  • May 22, 2017
takashi wrote:

Another possible approach: split the source file path with an AttributeSplitter (Delimiter: \\), then extract the third element from the last of the resulting list with a ListIndexcer (List Index: -3).

Thanks takashi, this is a very helpful option!

 

 


Reply


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