Skip to main content

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

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


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


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).


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.

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.

 


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 =)

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!

 


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