'''I am currently trying to copy files from one folder to another folder using shutil but I can't seem to get it to work, the process is saying it has finished but nothing happens?'''
The current criteria I have added raw_input that lets the user choose file extension. The next criteria I am looking to add is a date range function so I can choose a date range for example: 17/07/2020 to 04/08/2020 or the day's date.
*UPDATED CODE
import os
import shutil
import os.path, time
from pip._vendor.distlib.compat import raw_input
os.chdir('C://')
src = ("C:/Users/eldri/OneDrive/Desktop/")
dst = ("C:/Users/eldri/OneDrive/Desktop/output")
ext = raw_input("[+] File format: ")
created = (" last modified: %s" % time.ctime(os.path.getmtime(src)))
start = raw_input("[+] Date start: ")
end = raw_input("[+] Date end: ")
def date_to_num(date):
return int("".join(date.split('/')[::-1]))
def date_in_range(date, start, end):
return date_to_num(date) > date_to_num(start) and date_to_num(date) < date_to_num(end)
for filename in os.listdir(src):
if filename.endswith('.'+ext) and created.startswith(start) and created.endswith(end):
shutil.copy( src + filename, dst)
print("[+] File transferred "+filename + created)
else:
print("[+] File not transferred "+filename + created)
print("[+] Transfer complete")
I was looking at maybe pandas? but not sure as still quite new to python.
example on terminal
file extension = .csv
startdate = 12/05/2020
enddate = 07/08/2020
once the user has input these fields it would copy only the required files over.
The current output of the created files are:
[+] File transferred BASE1011.xls last modified: Fri Jul 17 10:11:40 2020
[+] File transferred BASE1112.xls last modified: Fri Jul 17 10:11:40 2020
[+] File transferred BASE1213.xls last modified: Fri Jul 17 10:11:40 2020
[+] File transferred BASE1314.xls last modified: Fri Jul 17 10:11:40 2020
[+] File transferred BASE1415.xls last modified: Fri Jul 17 10:11:40 2020
I want these to be in an easier format for user input as explained above: example: start 12/05/2020 end date = 07/08/2020
Thank you for your help, I am not the best at python but I am trying to learn so any help would be amazing.
Thanks