Please excuse my ignorance, I am new to programming and python, the code below allows me copy file if and only if it was modified in the last 24 hours.
Is there a better way I can twist my program to consider also the last 8 character which is the date the file was created _20191108. Files are usually as presented below
- 7***_13_01_2172_20191106.txt
- 7***_13_01_2174_20191107.txt
- 7***_12_01_2175_20191108.txt
7***_13_01_2176_20191108.txt
import time import os import shutil giorno = 24 * 60 * 60 src = 'C:/Users/Daniels/Desktop/FileMover/SourceA' dst = 'C:/Users/Daniels/Desktop/FileMover/SourceB' now = time.time() primo = now - giorno def last_mod_time(file_name): return os.path.getmtime(file_name) for file_name in os.listdir(src): src_filename = os.path.join(src, file_name) if last_mod_time(src_filename) > primo: dst_filename = os.path.join(dst, file_name) shutil.copy(src_filename, dst_filename) print(file_name)
Thank you!