Skip to main content
Solved

Copy/rename file with Python


dustin
Influencer
Forum|alt.badge.img+30

I'm looking to do something that I'm not sure is totally possible, but I'm trying. My goal is to copy a seed MDB file for each unique input attribute value, and rename to that value. I could have upwards of 200 unique names, and there will be one feature enter the PythonCaller per unique attribute. This is where my lackluster Python skills have taken me. The exception I'm getting is 'global name library is not defined'.

I have a feeling that even if this did process through as it is, I would only get one mdb copy with the first feature to pass through.

Best answer by ebygomm

Is there a reason for using python over the file copy writer?

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

3 replies

ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • Best Answer
  • March 19, 2019

Is there a reason for using python over the file copy writer?


dustin
Influencer
Forum|alt.badge.img+30
  • Author
  • Influencer
  • March 19, 2019
ebygomm wrote:

Is there a reason for using python over the file copy writer?

Wow, I was really overthinking this. I had never used the FileCopyWriter before now. Thanks!

david_r
Evangelist
  • March 20, 2019

I completely agree with @egomm, but nevertheless, here's a suggestion for a PythonCaller just in case:

import fmeobjects
import shutil

def processFeature(feature):
    library = feature.getAttribute('library_name')
    shutil.copyfile('e:\\seed.mdb''e:\\project\\%s.mdb' % library)

If you have duplicate values for library_name entering the PythonCaller, you could prefix it with a DuplicateFilter to only retain the unique values.


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