Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find 'yesterdays files'
#1
Greetings!
I guess the question is not new, but I cannot find a clan small snippet.
I found one here, on this forum - it has a function and 25 lines of code, it is not small or clean.

Anyway, need to scan a directory and find (and copy) files created yesterday.
I got this so far:
import os
import time
import datetime
today = datetime.date.today()
td = today.ctime()
print(f" Today --> {td}")

dirtoscan = "c:\\0001\\"
for fl in os.listdir(dirtoscan) :
    f_path = os.path.join(dirtoscan,fl)
    modified = os.path.getmtime(f_path)
    dateModif = time.ctime(modified)
    print(f"File Modif --> {dateModif}") 
I could split 'td' get a Second Element of spit
td = today.ctime()
And Split 'datemodif' to get Second Element of split
dateModif = time.ctime(modified)
and compare them, but it looks awful, ugly kind of code...
Thank you.
Reply


Messages In This Thread
find 'yesterdays files' - by tester_V - Jun-16-2021, 09:50 PM
RE: find 'yesterdays files' - by Gribouillis - Jun-16-2021, 10:30 PM
RE: find 'yesterdays files' - by Yoriz - Jun-16-2021, 11:01 PM
RE: find 'yesterdays files' - by tester_V - Jun-17-2021, 12:22 AM
RE: find 'yesterdays files' - by Gribouillis - Jun-17-2021, 06:01 AM
RE: find 'yesterdays files' - by tester_V - Jun-17-2021, 05:24 PM
RE: find 'yesterdays files' - by Yoriz - Jun-17-2021, 05:44 PM
RE: find 'yesterdays files' - by snippsat - Jun-17-2021, 06:21 PM
RE: find 'yesterdays files' - by tester_V - Jun-18-2021, 02:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find duplicate files in multiple directories Pavel_47 9 2,927 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  count every 28 files and find desire files RolanRoll 3 2,019 Dec-12-2021, 04:42 PM
Last Post: Axel_Erfurt
  Have to use Python 2.x to find "yesterday' files tester_V 6 2,770 Sep-19-2021, 12:26 AM
Last Post: tester_V
  Find and replace in files with regex and Python Melcu54 0 1,825 Jun-03-2021, 09:33 AM
Last Post: Melcu54
  List of error codes to find (and count) in all files in a directory tester_V 8 3,584 Dec-11-2020, 07:07 PM
Last Post: tester_V
  helping PyInstaller To Find files Harshil 0 1,441 Aug-30-2020, 10:16 AM
Last Post: Harshil
  Find specific subdir, open files and find specific lines that are missing from a file tester_V 8 3,488 Aug-25-2020, 01:52 AM
Last Post: tester_V
  python 3 find difference between 2 files pd007 2 2,079 May-22-2020, 01:16 AM
Last Post: Larz60+
  Find all “*.wav” files that created yesterday on linux host with python. pydeev 6 4,704 Jan-07-2020, 06:43 AM
Last Post: pydeev
  python script cant find folder where files are kept Shameendra 2 2,730 Nov-23-2018, 04:46 PM
Last Post: Shameendra

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020