i am trying to remove the folder variable "name" if its been in the folder longer than X amount of time. Can i run this script in admin mode without having to "right click" and run as admin? If i try to automate this script i would need something to that nature. I try using the os.remove function but i get an error below:
Error
PermissionError: [WinError 5] Access is denied:
Code:
for root, folders, files in os.walk('\\\MYDATA\\user$\\test\\Documents\\chris2020\\test.fof'):
for name in folders:
    datetimeFormat = '%Y-%m-%d %H:%M:%S.%f'
    filedate = str(datetime.fromtimestamp(os.path.getmtime(os.path.join(root, name))))
    now_time = str(datetime.now())
    now_time = datetime.strptime(now_time, datetimeFormat)
    filetime = datetime.strptime(filedate, datetimeFormat)
    difference = now_time-filetime
    if difference > timedelta(days=2):
        print(filetime)
        print(difference)
        print('Hi')
        # os.remove('\\\MYDATA\\user$\\test\\Documents\\chris2020\\test.fof\\' + name)
        shutil.rmtree('\\\MYDATA\\user$\\test\\Documents\\chris2020\\test.fof\\' + name)
        file_times = os.path.join("\\\MYDATA\\user$\\test\\Documents\\chris2020\\test.fof\\", name), ": ", str(
            difference)
        file_times_final.append(file_times[0] + file_times[1] + file_times[2])
    else:
        print("None")
        break
 
    