Do you get an error message?
In your code the object "photo" is a list, but you try to assign the list to a regular attribute which expects a number or a string object.
You'll have to either concatenate your list into a string, e.g.
photo_str = ', '.join(photo)
feature.setAttribute('photo', photo_str)
or write the contents into an FME list, notice the brackets in the attribute name:
feature.setAttribute('photo{}', photo)
Why not use the "Directory and File Path" reader.
That reader gets you all the names (and paths) of the files.
Then use the Aggregator to create a list of the file names.
Seems like the result you need.
Do you get an error message?
In your code the object "photo" is a list, but you try to assign the list to a regular attribute which expects a number or a string object.
You'll have to either concatenate your list into a string, e.g.
photo_str = ', '.join(photo)
feature.setAttribute('photo', photo_str)
or write the contents into an FME list, notice the brackets in the attribute name:
feature.setAttribute('photo{}', photo)
The FMEObjects Python API supports setting list attribute values without the curly braces:
>>> from fmeobjects import FMEFeature
>>> f = FMEFeature()
>>> f.setAttribute('foo', u'bar', 'baz'])
>>> f.getAttribute('foo')
f'bar', 'baz']
From the script you've pasted, it looks like line 13 is sitting outside of the processFeature() method definition, so you may be seeing a NameError. Try indenting it one level.
Hi @lucie
@erik_jan already gave this solution but since there was no response I am positing it again with an example of the implementation. Is there a reason why you want to go for a python implementation while there is a straightforward FME implementation?
The Directory and File Path reader allows you to list all files and/or directories in a specific directory. You can even apply some sort of regex-constraint (e.g. all filename have to start with 'create' in the example below). The reader lists all the information available for the files found and allows you to aggregate all the path_rootnames (the filename without extension) into on attribute.
Thank you to everyone.
I will use directly FME implementation as @
jeroenstiers has explained.
The FMEObjects Python API supports setting list attribute values without the curly braces:
>>> from fmeobjects import FMEFeature
>>> f = FMEFeature()
>>> f.setAttribute('foo', f'bar', 'baz'])
>>> f.getAttribute('foo')
g'bar', 'baz']
Nice, thanks for the info!
Hi @lucie
Could you close your question If you've got an answer on it?