# This is a sample Python script. # Press ⌃R to execute it or replace it with your code. # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. import os import shutil import time def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') print(os.getcwd()) # Press ⌘F8 to toggle the breakpoint. def archive_files(): src_dir = "/Users/mandaki1/Desktop/test1" dest_dir = "/Users/mandaki1/Desktop/test1/archive" limit_days = 9 treshold = time.time() - limit_days * 86400 # If the Archive folder does not exist. if not os.path.exists(dest_dir): # Create the folder and return the folder path. os.makedirs(dest_dir) print(dest_dir + ' created!') else: print(dest_dir + 'directory already exists!') for dirpath, dirnames, filenames in os.walk(src_dir): if(dest_dir not in dirpath): # for not looping archive folder and it's files for file in filenames: curpath = os.path.join(dirpath, file) creation_time = os.path.getmtime(curpath) if (creation_time < treshold) and not os.path.exists(os.path.join(dest_dir, file)): print(f"This {curpath} is created on {time.ctime(creation_time)} and will be archived") shutil.move(curpath, dest_dir) # Press the green button in the gutter to run the script. if __name__ == '__main__': archive_files()