0

how to figure out Recently added file in folder, is there a way to find out which files were added into a specific folder after a certain point of time?

They could be created/modfifed/accessed long before but I want to know if a file was newly added to a folder.

os.path.getctime(file) will get me created time but how shall I get the time a file was added to a folder and the name of the recently added file

  • Possible duplicate of [How do I watch a file for changes?](https://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes) – Daniel Butler Apr 24 '19 at 11:29
  • If you want a list of files added after a certain time you will have to use os.walk() on a certain directory and filter out the files with ctime. This is a good starting Point https://stackoverflow.com/questions/1176441/how-to-filter-files-with-known-type-from-os-walk/10812969 – mbieren Apr 24 '19 at 11:49

1 Answers1

0

Not the most elegant solution but an easy one:

import time

directory = r'some\folder\path'
interval = 60 #time in seconds
old_f = []
for (filenames) in os.walk(directory):
    old_f.extend(filenames)

time.sleep(interval)

new_f = []
for (filenames) in os.walk(directory):
    new_f.extend(filenames)

new_files = list(set(new_f) - set(old_f))

print('Changed files:', new_files)
GittingGud
  • 315
  • 2
  • 16