I see a problem here.
While using .getctime the string you are passing is not a proper file-path. You are concatenating pth with \filename. This syntactically worng.
You are missing the \ or other delimiter used in different os for specifying directories.
You can try the below answer -
import os
import datetime
pth = r"my_path"
def listDir(dir):
fileNames = os.listdir(dir)
for fileName in fileNames:
file_path = os.path.join(pth, fileName)
ts = os.path.getctime(file_path) # this returns the creation timestamp.
dt = datetime.datetime.fromtimestamp(ts) # this converts the timestamp to datetime object.
print('Nombre: {0} --> {1}'.format(fileName ,dt.date())) # dt.date() will return only the date from the datetime object.
listDir(pth)
Notes:
Use os.path.join for concatenating the paths as it takes care of which OS you are using. We don't have to worry about / or \\ or any other delimiter.
Convert the date into datetime object as manipulating and dealing with datetime object will be much more easier than dealing with strings.