1

I have a list of file path within a sub-directory. How can I find the created date for each of the file paths? I used the code below to get all the files within each sub-directory using Python:

def find(pattern, path):
    result = []
    for root, dirs, files in os.walk(path):
        for name in files:
            if fnmatch.fnmatch(name, pattern):
                result.append(os.path.join(root, name))
    return result

find(pattern, Path)
Rashid 'Lee' Ibrahim
  • 1,357
  • 1
  • 9
  • 21
T17
  • 71
  • 7

1 Answers1

1

Try one of these functions:

os.path.getmtime(file_path) or os.path.getctime(file_path)

OnlyDryClean Codzy
  • 943
  • 1
  • 10
  • 19
  • More discussion on details here: https://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python – bogovicj Mar 19 '20 at 14:28
  • @OnlyDryClean Codzy: I've put the filenames into a dataframe would I just refer to column name with the file_path? – T17 Mar 19 '20 at 14:30
  • @T17 No, you can't :) You can use map function https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html or apply https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html – OnlyDryClean Codzy Mar 19 '20 at 14:34