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.