1

Using Python 3.6, I'd like to find all files (with all possible extensions) on my computer (with OS Windows) which were created or modified after 5 December 2018. Could you please tell me, how can I solve this problem?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Leonid
  • 35
  • 6
  • You should look up the parents drive and check for modification time on all files. See this pointer at: https://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python – Umar Yusuf May 25 '19 at 21:15
  • Umar Yusuf, thank you! – Leonid May 25 '19 at 21:18
  • If you were helped by my answer, you can accept it by clicking on the green checkmark next to it. – miike3459 May 25 '19 at 21:30

1 Answers1

1

Here's a solution I found (works in Python 3.3 and above, because it uses pathlib). This changes your current directory to the root directory and does the calculations on all descendent files recursively:

import time, os, os.path

def get_new_paths():
    os.chdir("/")
    for path in pathlib.Path("/").glob("**/*"):  # Do a recursive search across all files
        if os.path.getmtime(path) > 1543986000:
            yield path

1543986000 is the exact timestamp of December 5th, 2018, 00:00:00 GMT. Just be mindful that your computer probably has millions of files and this will definitely eat up a lot of RAM.

miike3459
  • 1,431
  • 2
  • 16
  • 32
  • Thank you very much! How did you convert 5 December 2018 to 1543986000? Using the following code: import time, datetime; date1 = "05/12/2018"; time.mktime(datetime.datetime.strptime(date1, "%d/%m/%Y").timetuple()) I obtained 1543968000.0 – Leonid May 25 '19 at 21:43
  • @Leonid I just guesstimated until I found the correct value. I hope I didn't copy an incorrect value. – miike3459 May 25 '19 at 22:04