Hi everyone,
I modified the FilePropertyExtractor created by Takashi Iijima to suite my needs but it doesnt seems to store the attribute value correctly.
The Python code in PythonCaller below is to get multiple file from a folder and get the file's creation date (modified, etc.....)
It runs without error. Since the files in my folder was of different creation dates, I expect the output will follow accordingly as well but somehow only one date was shown for every outputs rows.
The print statement does show different value though.
I suspect that I must have missed the part that ensure the values are properly stored and returned.
Pls help me to correct it.
# Original Implementation by Takashi Iijima, 2016-05-25
# This a modified version
import fme, fmeobjects
import os
def extractFileProperty(feature):
try:
path = feature.getAttribute('__filepropertyextractor.path')
for file in os.listdir(path):
fullFileName=os.path.join(path,file)
if os.path.exists(fullFileName) and not os.path.islink(fullFileName):
s = os.stat(fullFileName)
feature.setAttribute('_file_type', 'File' if os.path.isfile(fullFileName) 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))
print (int(s.st_ctime))
else:
raise Exception('specified file/directory does not exist')
except Exception as ex:
feature.setAttribute('__filepropertyextractor.error', '%s' % ex)