I got the same errors that you did. First, I had to move line 4 after "file" is defined, or, in this case, "f". Then, the second error was the syntax of the print command. If you place a comma before timestr, it should print fine. The third problem was that I was getting permission denied, apparently from trying to open a whole directory.
I have rewritten some of your script to something that I think better suits your needs.
import glob
import time
import os
timestr = time.strftime("%Y%m%d_%H%M%S")
files = glob.glob('*.*')
for file in files:
print('created: %s' % time.ctime(os.path.getctime(file)), timestr)
print('last modified: %s' % time.ctime(os.path.getmtime(file)), timestr)
However, seeing your first posted example, I thought I could modify this to match it. Here's what I came up with:
import glob
import time
import os
files = glob.glob('*.*')
print(' created modified file_name')
for file in files:
print('%s' % time.strftime("%Y%m%d_%H%M%S", time.gmtime(os.path.getctime(file))), end=' ')
print('%s' % time.strftime("%Y%m%d_%H%M%S", time.gmtime(os.path.getmtime(file))), end=' ')
print(file)
Running it gave me:
created modified file_name
20170723_223307 20170723_223307 36e73b41-4366-4bf8-825f-9f16e41b1b41.tmp
20160928_232029 20171116_081039 desktop.ini
20171124_215147 20171124_215413 help.py
20171124_215637 20171124_221613 help2.py
20171124_214353 20171124_214353 test.txt
Now, it's just a matter of you getting the parameters on the right places and configuring the print commands to suit your exact needs.
Edit: With the request to extract EXIF data, the code looks like this. Forgive the blank except.
import glob
import time
import os
from PIL import Image
files = glob.glob('*.*')
print(' created modified EXIF file_name')
for file in files:
print('%s' % time.strftime("%Y:%m:%d %H:%M:%S", time.gmtime(os.path.getctime(file))), end=' ')
print('%s' % time.strftime("%Y:%m:%d %H:%M:%S", time.gmtime(os.path.getmtime(file))), end=' ')
try:
print('%s' % Image.open(file)._getexif()[36867], end=' ')
except:
print('Not an image', end=' ')
print(file)
Remember that you can adjust glob to only get jpg, png, or whatever you want. This script gets everything and if it's not an image, it just prints that it failed.