Instantly share code, notes, and snippets.

@iredun /bk.py
Created Feb 19, 2018

Embed
What would you like to do?
The python script at the start of which copies all the files in the View folder in the "Download" folder to the folder in the format %d_%m_%Y_bk, also moves the previously created folders every week to a folder of the format %d_%m_%Y_week_db
import shutil
import os
import datetime
from winreg import *
with OpenKey(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders') as key:
Downloads = QueryValueEx(key, '{374DE290-123F-4565-9164-39C4925E467B}')[0]
main_folder = Downloads + "\\"
now = datetime.datetime.now()
source = os.listdir(main_folder)
destination = main_folder + now.strftime("%d_%m_%Y") + "_bk\\"
for files in source:
if not files.endswith("_bk") and files != "Telegram Desktop":
if not os.path.exists(destination):
os.makedirs(destination)
shutil.move(main_folder + files, destination)
curWday = now.strftime("%w")
if (curWday == '0'):
source = os.listdir(main_folder)
destination = main_folder + now.strftime("%d_%m_%Y") + "_week_bk\\"
for files in source:
if files != "Telegram Desktop":
if not os.path.exists(destination):
os.makedirs(destination)
shutil.move(main_folder + files, destination)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment