Hi FME'ers
when creating a list with the following Python script:
import fme, os
import fmeobjects
folder = os.path.dirname(FME_MacroValues['Folder'])
def get_filepaths(feature): """ This function will generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames). """
file_paths = [] # List which will store all of the full filepaths.
# Walk the tree.
for root, directories, files in os.walk(folder):
for filename in files:
# Join the two strings in order to form the full filepath.
if '.dwg' in filename and '_georeferenced.dwg' not in filename:
filepath = os.path.join(root, filename)
file_paths.append(filepath) # Add it to the list.
feature.setAttribute('file_paths', file_paths)
I cannot easily retrieve the list of folders in FME.
I tried AttributeExposer with value 'file_paths{}', but it doesn't work
the AttributeExploder works and is a good workaround, but I'm curious how I could improve the script and expand my Python skills.
Thanks in advance for your help.
best regards,
Jelle