Answers for "Is the way I implement fme feature setattribute correct for my purpose?" https://knowledge.亚搏在线safe.com/questions/32757/is-the-way-i-implement-fme-feature-setattribute-co.html The latest answers for the question "Is the way I implement fme feature setattribute correct for my purpose?" Answer by takashi https://knowledge.safe.com/answers/32763/view.html

Hi@hunphenglim, if you need to extract file properties for each file under a specified directory, you will have to define aclassrather than a function.This is an example (error handling is omitted).

import os class FilePropertyExtractor(object): def input(self, feature): dir = feature.getAttribute('__filepropertyextractor.path') if os.path.exists(dir) and os.path.isdir(dir) and not os.path.islink(dir): for file in os.listdir(dir): path = os.path.join(dir, file) if not os.path.islink(path): s = os.stat(path) feature.setAttribute('_file_name', file) feature.setAttribute('_file_type', 'File' if os.path.isfile(path) else 'Directory') feature.setAttribute('_file_size', s.st_size) feature.setAttribute('_file_atime', int(s.st_atime)) feature.setAttribute('_file_mtime', int(s.st_mtime)) feature.setAttribute('_file_ctime', int(s.st_ctime)) self.pyoutput(feature)

However, it might be easier to use the Directory and File Pathnames (PATH) reader with setting 'YES' to the 'Retrieve file properties' parameter in this case.

Thu, 25 Aug 2016 04:41:08 GMT takashi