Solved

FileNamePartExtractor for Multiple Files

  • 15 December 2015
  • 19 replies
  • 38 views

Badge

Hi Experts,

I am merging many csv files into one and I want to get the name of the input file in an attribute 'filename'. I am using FileNamePartExtractor for this purpose and its working correct with single input. But, when I use this with multiple files, it takes the name of the last input file and shows in all the rows. Can anyone help me with where I am going wrong!!

icon

Best answer by pratap 15 December 2015, 05:51

View original

19 replies

Userlevel 2
Badge +17

How did you set the "Source Filename" parameter of the transformer?

Badge

How did you set the "Source Filename" parameter of the transformer?

Yes. I put the Source name as a parameter and gave the parameter name to the Source FileName. I am running the wb using Prompt and run Translation and the name of the last file is displayed only. Rest all attributes are perfect.

Badge +2

Hi,

Use AttributeExposer and expose the attribute fme_dataset and select "fme_dataset" in "Source Filename" parameter of the FilenamePartExtractor.

Pratap

Userlevel 2
Badge +17

Yes. I put the Source name as a parameter and gave the parameter name to the Source FileName. I am running the wb using Prompt and run Translation and the name of the last file is displayed only. Rest all attributes are perfect.

The user parameter value will be a space separated file paths string when you selected multiple files. That's why you couldn't accomplish your goal. I think @pratap's answer is a general usage of the FilenamePartExtractor.

In addition, you can expose "fme_dataset" in the reader feature properties dialog (Format Attributes tab).

Badge

Hi @takashi and @pratap

I was going through system parameters page and was wondering if I can also use this as posted by @RobynAtSafe.

Badge +2

Hi,

:) There will be so many ways to attain the required result. Its up to you to decide which is optimum.

Pratap

Userlevel 2
Badge +17

Hi @takashi and @pratap

I was going through system parameters page and was wondering if I can also use this as posted by @RobynAtSafe.

I cannot understand how your question about the FilenamePartExtractor is related to the system parameters and Robyn's article. New question?

Badge

Hi @takashi and @pratap

I was going through system parameters page and was wondering if I can also use this as posted by @RobynAtSafe.

FilenamePartExtractor with AttributeExposer(for Multiple Files) gives us the file location, so as the system parameter FME_MF_DIR does. On the other hand, AttributeFileReader with StringConcatenator gives the same output as written by Robyn. I tried using Robyn's method but sadly it didn't work. Does both work the same way or Robyn's idea work only on databases? Can we use them while writing shps, XMLs etc.?

Userlevel 4
Badge +13

FilenamePartExtractor with AttributeExposer(for Multiple Files) gives us the file location, so as the system parameter FME_MF_DIR does. On the other hand, AttributeFileReader with StringConcatenator gives the same output as written by Robyn. I tried using Robyn's method but sadly it didn't work. Does both work the same way or Robyn's idea work only on databases? Can we use them while writing shps, XMLs etc.?

Note -- FME_MF_DIR is the directory where your workspace lives. It is NOT where the data is. It is very unlikely that FME_MF_DIR would be helpful for the scenario in the original question.

Userlevel 2
Badge +17

Hi @takashi and @pratap

I was going through system parameters page and was wondering if I can also use this as posted by @RobynAtSafe.

Regarding FME_MF_DIR parameter, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets."

In my experiences, however, the parameter always contains the folder path in which the current workspace file (*.fmw) is saved. I've never seen the case where it contains "the location of the source datasets".

Robyn's workspace example doesn't use FME_MF_DIR. The StringConcatenator just concatenates a specific folder path and an attribute value storing a file name to create a full file path, and then the AttributeFileReader reads the contents of a file specified by the path.

How can you apply those to your purpose?

I think that your question was how to extract parts from each file path string, when multiple files have been selected as dataset of the reader. Am I wrong?

# I would like to know when FME_MF_DIR will contain "the location of the source datasets".

Userlevel 2
Badge +17

Note -- FME_MF_DIR is the directory where your workspace lives. It is NOT where the data is. It is very unlikely that FME_MF_DIR would be helpful for the scenario in the original question.

@daleatsafe, however, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets." I've never seen such a case. Could you please clarify this?

Userlevel 4

@daleatsafe, however, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets." I've never seen such a case. Could you please clarify this?

Could it be that they're thinking of all those who put the workspace and the data in the same folder? I've certainly seen that quite a lot, in particular with occasional FME users.

Userlevel 2
Badge +17

@daleatsafe, however, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets." I've never seen such a case. Could you please clarify this?

Hi @david_r, thanks for your comment. Surely there are cases that all source data files are saved in the same folder as the workspace file. In such a case, FME_MF_DIR indicates the location of the source datasets, but it's a matter of course. As a description on the parameter, it's not necessary to be mentioned particularly, so I had supposed that there are other special cases where FME_MF_DIR indicates the location of source datasets even though it's not the same as the workspace location. Thinking too much...

Userlevel 2
Badge +17

@daleatsafe, however, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets." I've never seen such a case. Could you please clarify this?

Maybe my misinterpretation about "and, in some cases". Natural languages are more difficult to understand correctly than program languages.

Userlevel 4
Badge +25

Could it be that they're thinking of all those who put the workspace and the data in the same folder? I've certainly seen that quite a lot, in particular with occasional FME users.

Yes, probably when you create the workspace from a template. But I agree that it's not definite and perhaps not that common.

Userlevel 4
Badge +13

Maybe my misinterpretation about "and, in some cases". Natural languages are more difficult to understand correctly than program languages.

We should remove that inference in the documentation. FME_MF_DIR is the workspace directory, that is all. If your data happens to be there, congratulations. But I wouldn't want to make that leap in the doc. I've asked the team to adjust it. Thanks

Userlevel 2
Badge +17

@daleatsafe, however, the documentation says "Contains the name of the folder in which the current workspace resides and, in some cases, the location of the source datasets." I've never seen such a case. Could you please clarify this?

@daleatsafe, thanks for your clarification. My long time question has been resolved at last :-)
Badge

Hi,

Use AttributeExposer and expose the attribute fme_dataset and select "fme_dataset" in "Source Filename" parameter of the FilenamePartExtractor.

Pratap

I had the same issue, and I tried the above - it worked! Thank you so much!

Badge +2

I had the same issue, and I tried the above - it worked! Thank you so much!

@watts Its good to hear...

Many Thanks for acknowledgement

Reply