Jul-22-2023, 11:14 AM
(This post was last modified: Jul-22-2023, 11:17 AM by deanhystad.)
If you can't install pendulum you could fall back to constructing a start of day timestamp.
from datetime import datetime, date, time, timedelta from zoneinfo import ZoneInfo from pathlib import Path items = '/somehost/c$/directory/' # <--- Some Host in Asia/Kuala_Lumpur ndir_p = 'D:somedir/' # <--------------- Directory for files from Kuala_Lumpur # Get timestamps for start of today and start of yesterday. # Use tzinfo=ZoneInfo('Asia/Kuala_Lumpur') to get these for Kuala Lumpur. today = datetime.combine(date.today(), time(), tzinfo=ZoneInfo("America/Vancouver")) yesterday = (today - timedelta(hours=24)).timestamp() today = today.timestamp() for echf in Path(items).iterdir(): if echf.is_file(): if yesterday <= echf.stat().st_mtime < today: # There will be zero gap and zero overlap if you run this once every day. try: shutil.copy2(echf, ndir_p) except OSError as st : print(f" -- {st}")