Python Forum
Windows Disk Cleanup Code Help Needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows Disk Cleanup Code Help Needed
#1
Hi all.

I am trying to generate Python code to do the following:
Access the Windows Disk Cleanup program and clear out the regular and system files with full admin rights, and also without having the Python pop up window occur during the program execution.

The following is what I have so far, (when running the program it says completed but when I open the Disk Cleanup app and check.... nothing has been erased. I also get an Access is denined message as well. Any help would be greatly appreciated in modifying the following code to work as intended in the above-mentioned:

import os import hashlib import time class Duplython: def __init__(self): self.home_dir = os.getcwd() self.File_hashes = [] self.Cleaned_dirs = [] self.Total_bytes_saved = 0 self.block_size = 65536 self.count_cleaned = 0 def welcome(self) -> None: print("**************** DUPLYTHON ****************************") print("Cleaning...") time.sleep(3) def generate_hash(self, filename: str) -> str: filehash = hashlib.sha256() try: with open(filename, "rb") as file: file_block = file.read(self.block_size) while len(file_block) > 0: filehash.update(file_block) file_block = file.read(self.block_size) filehash = filehash.hexdigest() return filehash except: return False def clean(self) -> None: all_dirs = [path for path, _, _ in os.walk(".")] for path in all_dirs: os.chdir(path) all_files = [file for file in os.listdir() if os.path.isfile(file)] for file in all_files: file_hash = self.generate_hash(file) if file_hash not in self.File_hashes: if file_hash: self.File_hashes.append(file_hash) else: byte_saved = os.path.getsize(file) self.count_cleaned += 1 self.Total_bytes_saved += byte_saved os.remove(file) filename = file.split("/")[-1] print(f"{filename} cleaned") os.chdir(self.home_dir) if __name__ == "__main__": App = Duplython() App.welcome() App.clean()[quote][/quote]
Gribouillis write Jul-17-2024, 09:04 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Where do you attempt to access the Windows Disk Cleanup program?
Reply
#3
(Jul-18-2024, 03:25 PM)deanhystad Wrote: Where do you attempt to access the Windows Disk Cleanup program?

C:\Windows\System32
Reply
#4
Where in your program do you try to use the windows disk cleanup program?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mirroring disk structures in nested dictionaries Curbie 16 4,532 Apr-27-2025, 02:43 PM
Last Post: deanhystad
  DEC pack, unpack and disk-images Curbie 32 10,557 Aug-23-2024, 03:37 PM
Last Post: Curbie
  Hard disk structure like a file selection dialog malonn 2 2,520 Aug-09-2023, 09:14 PM
Last Post: malonn
  Code Assistance needed in saving the file MithunT 0 1,723 Oct-09-2022, 03:50 PM
Last Post: MithunT
  How to Translate a python code written in Mac-OS to Windows? alexanderDennisEnviro500 2 5,100 Jul-31-2021, 08:36 AM
Last Post: Gribouillis
  [split] SyntaxError when trying to execute code on Windows nehaya 2 3,087 Aug-04-2020, 11:18 AM
Last Post: nehaya
  How to Calculate CPU, Disk, Memory and Network utilization rate skvivekanand 1 3,171 Jun-16-2020, 08:53 PM
Last Post: jefsummers
  Explanantion needed in part of code... jayg320 6 6,311 Apr-26-2020, 11:33 AM
Last Post: anbu23
  SyntaxError when trying to execute code on Windows Fred0n 2 3,821 Apr-25-2020, 04:30 AM
Last Post: buran
  how to write offset number to disk use python? Pyguys 4 5,162 Apr-11-2020, 07:53 AM
Last Post: Pyguys

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.