Skip to main content
Solved

Access to CSV filename in python

  • February 15, 2017
  • 4 replies
  • 12 views

Hi there,

I am trying to digest multiple CSV files from within a certain directory. To do this, I have created a CSV Reader that has a Source CSV folder with the parameter: _"<my file path>\\*.csv"_.

I need to remove the processed file from this directory after processing which I would do via python shutdown script by getting the filename that has to be removed (actually - it would be moved into a directory).

In the past when I only processed one file, I was able to grab the file location directly from the reader, which is of course now the <filepath>*.csv .

I have used an Attribute-Exposer to get the filename- but I haven't figured out how to use it in my shutdown script? Am I missing something obvious here? Is there a way to either:

- set a Python variable with the filename (I would be surprised)

or

- set a publish parameter at run-time?

Thanks in advance!

Best answer by erik_jan

I have done this using the FileCopy Writer using the fme_basename attribute that contains the file name and path. In that case there is no need for Python.

View original
Did this help you find an answer to your question?

4 replies

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • Best Answer
  • February 15, 2017

I have done this using the FileCopy Writer using the fme_basename attribute that contains the file name and path. In that case there is no need for Python.


Forum|alt.badge.img+7

Hi @robopetr

There is no possibility to retrieve attribute values in the shutdown script. You can however use parameters using the list FME_MacroValues['name_parameter']. The path can be retrieved and all csv-files can be fetched using this path.

Another solution is to expose the fme_ feature_type (so you get the name of every file) and make sure that one of the features (for example using a sampler grouped by the feature_type) is sent to a pythoncaller. Using FeatureHolders you can make sure this pythoncaller is only executed at the end.


Forum|alt.badge.img+7
erik_jan wrote:

I have done this using the FileCopy Writer using the fme_basename attribute that contains the file name and path. In that case there is no need for Python.

A cleaner and easier solution.

 

I would go for this one ;)

 

 


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • February 15, 2017
erik_jan wrote:

I have done this using the FileCopy Writer using the fme_basename attribute that contains the file name and path. In that case there is no need for Python.

yes much better and you keep the overview of actions in the workspace and not "hidden" in the shutdown script

 

 


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