Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import shutil
- import subprocess
- # Directories to search for temporary files
- temp_dirs = [r'C:\Windows\Temp',
- r'C:\Users\<UserName>\AppData\Local\Temp'] # rewrite username on ur without <>
- def delete_temp_files(dirs):
- error_deleting = False
- for temp_dir in temp_dirs:
- for root, dirs, files in os.walk(temp_dir):
- for file in files:
- file_path = os.path.join(root, file)
- try:
- os.remove(file_path)
- except Exception as e:
- error_deleting = True
- print(f'Error deleting {file_path}: {e}')
- subprocess.run(['explorer', root], check=True)
- if not error_deleting:
- print('Cleaning was successful!')
- print('''
- /\_/\
- ( o.o )
- > ^ <
- ''')
- if __name__ == '__main__':
- delete_temp_files(temp_dirs)
- # example of working
- # Cleaning was successful!
- #
- # /\_/\
- # ( o.o )
- # > ^ <
- # guys if u find error - paste it in comment please i junior in python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement