Keeping a Windows PC clean can make everyday computer use much more comfortable. Over time, applications, browsers, Windows components, and other programs can create temporary files and cached data that are no longer needed.
While individual temporary files are usually small, thousands of files can accumulate over time. This can make it difficult to understand what is taking up storage space and can leave a computer filled with unnecessary data.
That is why we created a simple PC Cleaner written entirely in Python.
The goal of this project is straightforward: provide users with an easy-to-use graphical application that can scan selected temporary locations, show how much removable data is present, and clean those locations without targeting personal files such as documents, photos, videos, or downloads.
The application is designed to be simple enough for beginners while still being useful for people who want a lightweight cleaning utility without installing a large third-party maintenance suite.
What Is the PC Cleaner?
The PC Cleaner is a small Windows desktop application built with Python.
Instead of requiring users to open Command Prompt and manually search through temporary folders, the application provides a graphical interface.
The main screen gives the user access to several cleaning categories:
User temporary files
Windows temporary files
Browser cache
Recycle Bin
Scan functionality
Cleanup functionality
Cleanup progress
A detailed activity log
The application is intentionally focused on common temporary and cached data rather than attempting to remove everything from the computer.
This is important because a cleaning application should prioritize safety and transparency.
Why Do Temporary Files Exist?
Temporary files are a normal part of using a computer.
Windows and applications frequently create temporary data while performing tasks.
For example, an application might create a temporary file while processing a large document. A browser can store cached images and website resources to make websites load faster the next time you visit them.
Installers can also create temporary files while installing or updating software.
These files are not necessarily bad.
In fact, many of them are useful while a program is running.
The problem is that some temporary data can remain after the original task has finished.
Over time, this can result in a large number of files occupying storage space.
The PC Cleaner is designed to help identify and remove selected temporary data that is generally intended to be disposable.
Main Features
The tool includes several useful features while keeping the interface simple.
1. User Temporary Files
The application can scan the user's temporary directory.
Windows applications commonly use this location to store temporary files.
The cleaner examines the directory and calculates the amount of data that can potentially be removed.
During cleanup, it attempts to remove files and folders from the selected temporary location.
Files that are currently being used by another application may not be removable.
Instead of stopping the entire cleanup process, the application skips files that Windows reports as unavailable.
2. Windows Temporary Files
The cleaner can also scan the Windows temporary directory.
This location can contain temporary data created by Windows and installed applications.
Because some files may be actively used by the operating system, the application does not assume that every file can be deleted.
If Windows prevents a file from being removed, the cleaner simply skips it.
This is one of the reasons the tool uses a conservative approach rather than attempting to force-delete protected files.
3. Browser Cache Cleaning
Modern browsers can store significant amounts of cached data.
The PC Cleaner can detect common browser cache locations for browsers such as:
Google Chrome
Microsoft Edge
Mozilla Firefox
Browser caches can contain items such as:
Cached images
Cached website resources
Temporary browser data
Code cache files
Deleting browser cache does not mean deleting your browsing history, bookmarks, saved passwords, or personal documents through the cleanup routines provided by this application.
The purpose is specifically to target cache directories.
After cache cleanup, some websites may initially load a little more slowly because the browser has to download certain resources again.
That is normal.
4. Recycle Bin
The application also includes an optional Recycle Bin cleanup.
This option is disabled by default.
That is intentional.
Files placed in the Recycle Bin can normally still be restored. Emptying the Recycle Bin removes that recovery option.
For that reason, users should only enable the Recycle Bin option when they are certain that they no longer need those files.
The cleaner uses Windows' PowerShell functionality to request that the Recycle Bin be emptied.
5. Scan Before Cleaning
One of the most important features is the separation between scanning and cleaning.
The application does not immediately delete files when the user launches it.
Instead, the user can click SCAN PC first.
The program examines the selected cleanup locations and calculates their approximate size.
The interface then reports the amount of data that may be removable.
This gives the user an opportunity to see what the program has found before starting the cleanup.
6. Cleanup Confirmation
After scanning, the user can select CLEAN PC.
Before performing the cleanup, the application displays a confirmation message.
This is an additional safety step.
The confirmation reminds the user that the cleaner is intended for temporary and cached data and that personal files such as documents, photos, videos, and downloads are not part of the normal cleanup targets.
The user can cancel the operation if they do not want to continue.
7. Progress Information
The application provides progress information while scanning and cleaning.
The status area can display messages such as:
Scanning your PC...
or:
Cleaning PC...
The application also provides an activity log.
This allows users to see which categories are being processed.
For example, the log can display information similar to:
Scanning: User temporary files
followed by the amount of data detected.
This makes the program more transparent than a tool that simply displays a final number without explaining what it did.
8. Space Calculation
The cleaner calculates the approximate size of files inside the selected directories.
For example, it can report values such as:
850.24 MB
or:
2.31 GB
The program automatically converts bytes into more readable units such as:
Bytes
KB
MB
GB
TB
This makes the scan results much easier to understand.
How the Cleaner Works
The application is written using standard Python libraries.
The main components include:
Tkinter
Tkinter is used to create the graphical interface.
It provides the buttons, checkboxes, progress bars, text areas, labels, and other interface elements.
os
Python's os module is used to work with Windows environment variables, folders, files, and paths.
shutil
The shutil module provides functionality for removing directories and working with file operations.
tempfile
The tempfile module helps identify the appropriate temporary directory.
subprocess
The application uses subprocess to communicate with Windows functionality when handling the Recycle Bin.
threading
Scanning and cleanup operations can take time, especially when there are thousands of files.
The program therefore performs these operations in background threads.
This helps prevent the graphical interface from becoming unresponsive while the cleaner is working.
Why Use Threads?
Imagine a temporary folder containing tens of thousands of files.
If the application attempted to calculate the size of everything directly on the main graphical interface thread, the interface could temporarily freeze.
That would create a poor user experience.
The PC Cleaner instead starts the scan in a background thread.
The same approach is used during cleanup.
The interface remains available while the program processes the files.
This is a small but important design decision for a desktop application.
Safety Approach
A PC cleaning application has to be careful.
Deleting the wrong files can cause applications to stop working or, in more serious cases, affect the operating system.
For that reason, this project intentionally avoids attempting to clean arbitrary locations across the entire computer.
The cleaner focuses on known temporary and cache locations.
It does not provide a button that says something like:
Delete everything unnecessary on my PC.
That type of approach would be difficult to define safely.
Instead, the application uses specific categories.
Users can decide which categories they want to scan and clean.
What the Cleaner Does NOT Target
The application is not designed to remove personal files.
It does not intentionally target:
Documents
Pictures
Videos
Music
Desktop files
Downloads
Personal folders
Installed applications
Windows system files in general
The idea is to keep the scope narrow.
A cleaner should not make assumptions about what a person considers important.
Why Browser Cache Can Become Large
Browsers are designed to store frequently used resources locally.
For example, when you visit a website, the browser may save images, scripts, fonts, and other resources.
When you return to the website, the browser can reuse some of those resources instead of downloading everything again.
This can improve loading performance.
However, the cache can grow over time.
For users with limited storage, periodically removing cache data can recover some space.
The trade-off is that the browser may need to download those resources again later.
What Happens During a Scan?
The process is relatively simple.
Step 1: Choose Categories
The user selects the categories they want to scan.
For example:
User temporary files
Windows temporary files
Browser cache
Step 2: Start the Scan
The user presses:
SCAN PC
Step 3: Analyze Locations
The application examines the selected directories.
It calculates the approximate size of their contents.
Step 4: Display Results
The application displays the detected sizes in the activity log.
Step 5: Review
The user can see how much data was found before cleaning.
Step 6: Clean
The user presses:
CLEAN PC
Step 7: Confirmation
The application asks the user to confirm.
Step 8: Cleanup
The cleaner attempts to remove the selected temporary data.
Step 9: Final Result
The application reports approximately how much data was removed.
What Happens If a File Cannot Be Deleted?
This is completely normal.
A temporary file might currently be used by:
Windows
Chrome
Edge
Firefox
An installer
Another application
Windows may therefore prevent the cleaner from deleting it.
The program handles these situations by skipping files that cannot be accessed or removed.
This is preferable to trying to forcibly terminate applications or bypass Windows protections.
The result may therefore be slightly different from the initial scan.
For example, the scan could report 1.5 GB of temporary data, while the cleanup removes 1.2 GB.
The remaining data may consist of files that were locked, protected, or otherwise unavailable.
How to Install Python
Before running the application, Python needs to be installed.
After installing Python, you can verify the installation by opening Command Prompt and running:
python --version
If Python is installed correctly, Windows should display the installed version.
The application itself does not require external Python packages because it uses standard Python libraries.
Running the PC Cleaner
Save the source code as:
pc_cleaner.py
Then open Command Prompt in the folder containing the file.
Run:
python pc_cleaner.py
The graphical interface should open.
From there, you can select the cleanup categories and begin scanning.
Turning the Python Program Into a Windows EXE
One of the most useful improvements is packaging the Python application as a standalone Windows executable.
That allows users who do not have Python installed to run the cleaner more easily.
A popular option is PyInstaller.
Install it with:
pip install pyinstaller
Then build the application with:
pyinstaller --onefile --windowed pc_cleaner.py
After the process finishes, PyInstaller creates a dist directory.
The executable can be found inside that directory.
For a polished release, the application can also be given a custom icon.
For example:
pyinstaller --onefile --windowed --icon=icon.ico pc_cleaner.py
The result can be distributed as a Windows application.
Ideas for Future Versions
The current version is intentionally simple, but there are many ways to expand it.
Disk Space Analyzer
A future version could show which folders consume the most storage.
For example:
Applications 45 GB
Videos 32 GB
Downloads 18 GB
Temporary files 4 GB
Other 9 GB
A graphical disk analyzer would make the tool significantly more useful.
Large File Finder
Another useful feature would be finding unusually large files.
Users could search for files larger than:
500 MB
1 GB
5 GB
10 GB
The tool could then show the file path and size without automatically deleting anything.
This would give users more control over their storage.
Duplicate File Finder
A future version could also identify duplicate files.
For example, a user might have the same video stored several times.
A duplicate finder could compare file hashes and identify identical files.
Importantly, duplicates should be presented for review rather than automatically deleted.
Startup Manager
Another possible feature would be a startup application manager.
It could show applications configured to launch when Windows starts.
The user could then decide which applications should remain enabled.
This should be implemented carefully because some startup entries may be important for hardware drivers or security software.
Windows Update Cleanup
Another potential feature would be integration with Windows' own storage-management functionality.
Rather than manually deleting system components, a future version could provide shortcuts to official Windows cleanup tools.
This is safer than attempting to manually remove sensitive Windows update files.
Dark Mode
The current interface uses the standard Windows Tkinter appearance.
A future version could introduce a modern dark interface.
For example:
PC Cleaner
Clean unnecessary files and recover storage.
With large buttons for:
SCAN PC
and:
CLEAN PC
A modern interface could make the program look more like a commercial Windows utility.
Scheduled Cleaning
Another possible feature would be scheduled scans.
For example, users could configure the application to remind them to perform a cleanup:
Weekly
Every two weeks
Monthly
Automatic deletion should be treated more cautiously than automatic scanning, because users may want to review what is going to be removed.
Portable Version
The application can also be packaged as a portable executable.
That means users could potentially keep it on a USB drive and run it on compatible Windows computers without going through a traditional installation process.
This could make the tool convenient for technicians and users who maintain multiple computers.
Lightweight by Design
One of the biggest advantages of this project is its simplicity.
It does not need a large database.
It does not require an online account.
It does not need a cloud service.
The basic cleaner can operate locally on the computer.
That makes it an interesting project for anyone learning Python desktop development.
It demonstrates several useful programming concepts in a single application:
GUI development
File system operations
Directory traversal
File size calculation
Error handling
Multithreading
Windows environment variables
Process execution
Progress reporting
User confirmation
Application packaging
Who Is This Tool For?
The PC Cleaner can be useful for several types of users.
Beginners
People who do not want to manually navigate Windows temporary directories can use the graphical interface.
Developers
The project is a good example of how Python can be used to create practical Windows utilities.
Students
It demonstrates real-world Python concepts without requiring a complicated framework.
PC Technicians
A portable version could provide a quick way to inspect common temporary-data locations.
Everyday Windows Users
Anyone who occasionally wants to remove accumulated temporary and cached files can use the application.
Important Reminder About Cleaning Software
No cleaning application should promise that it will magically make every computer faster.
Removing temporary files can recover storage space, but it does not automatically solve every performance problem.
A slow computer can have many different causes, including:
Insufficient RAM
High CPU usage
Background applications
Storage problems
Malware
Outdated drivers
Hardware limitations
Thermal throttling
Too many startup applications
Therefore, the PC Cleaner should be viewed primarily as a storage and temporary-file maintenance tool, not as a guaranteed performance booster.
Final Thoughts
The PC Cleaner is a simple example of how Python can be turned into a useful Windows desktop utility.
Instead of manually searching through temporary directories and browser cache folders, users can open one application, select the categories they want to inspect, scan the computer, review the results, and then perform the cleanup.
The project also provides a strong foundation for building a much larger Windows maintenance application.
Future versions could add disk analysis, duplicate detection, large-file discovery, startup management, scheduled scans, dark mode, portable builds, and a more modern interface.
Most importantly, the tool is designed around a simple principle:
Give users control over what gets cleaned.
It does not attempt to delete personal files or blindly remove unknown data from the computer.
If you decide to distribute the application publicly, clearly explain what the tool scans, what it can remove, and what it does not touch. Users should always understand what a cleaning application is going to do before they click the cleanup button.
With a few additional improvements, this small Python project can become the foundation for a complete lightweight Windows maintenance utility.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import os
import shutil
import tempfile
import threading
import subprocess
import tkinter as tk
from tkinter import ttk, messagebox
class PCCleaner:
def __init__(self, root):
self.root = root
self.root.title("PC Cleaner")
self.root.geometry("720x560")
self.root.minsize(650, 500)
self.scanning = False
self.cleaning = False
self.total_found = 0
self.total_deleted = 0
self.build_ui()
def build_ui(self):
main = ttk.Frame(self.root, padding=25)
main.pack(fill="both", expand=True)
title = ttk.Label(
main,
text="PC Cleaner",
font=("Segoe UI", 24, "bold")
)
title.pack(anchor="w")
subtitle = ttk.Label(
main,
text="Clean temporary and unnecessary files safely."
)
subtitle.pack(anchor="w", pady=(3, 20))
options = ttk.LabelFrame(main, text="Cleaning options", padding=15)
options.pack(fill="x")
self.temp_var = tk.BooleanVar(value=True)
self.windows_temp_var = tk.BooleanVar(value=True)
self.browser_var = tk.BooleanVar(value=True)
self.recycle_var = tk.BooleanVar(value=False)
ttk.Checkbutton(
options,
text="User temporary files",
variable=self.temp_var
).grid(row=0, column=0, sticky="w", padx=10, pady=7)
ttk.Checkbutton(
options,
text="Windows temporary files",
variable=self.windows_temp_var
).grid(row=0, column=1, sticky="w", padx=10, pady=7)
ttk.Checkbutton(
options,
text="Browser cache",
variable=self.browser_var
).grid(row=1, column=0, sticky="w", padx=10, pady=7)
ttk.Checkbutton(
options,
text="Recycle Bin",
variable=self.recycle_var
).grid(row=1, column=1, sticky="w", padx=10, pady=7)
buttons = ttk.Frame(main)
buttons.pack(fill="x", pady=20)
self.scan_button = ttk.Button(
buttons,
text="SCAN PC",
command=self.start_scan
)
self.scan_button.pack(
side="left",
fill="x",
expand=True,
padx=(0, 7),
ipady=8
)
self.clean_button = ttk.Button(
buttons,
text="CLEAN PC",
command=self.start_clean,
state="disabled"
)
self.clean_button.pack(
side="left",
fill="x",
expand=True,
padx=(7, 0),
ipady=8
)
self.progress = ttk.Progressbar(
main,
mode="indeterminate"
)
self.progress.pack(fill="x", pady=(0, 10))
self.status_var = tk.StringVar(value="Ready to scan.")
ttk.Label(
main,
textvariable=self.status_var
).pack(anchor="w")
results_frame = ttk.LabelFrame(
main,
text="Results",
padding=10
)
results_frame.pack(
fill="both",
expand=True,
pady=(20, 0)
)
self.results = tk.Text(
results_frame,
height=12,
state="disabled",
font=("Consolas", 9)
)
self.results.pack(fill="both", expand=True)
def get_cleanup_paths(self):
paths = []
if self.temp_var.get():
paths.append((
"User temporary files",
tempfile.gettempdir()
))
if self.windows_temp_var.get():
windows_temp = os.path.join(
os.environ.get("WINDIR", r"C:\Windows"),
"Temp"
)
paths.append((
"Windows temporary files",
windows_temp
))
if self.browser_var.get():
local = os.environ.get("LOCALAPPDATA", "")
chrome = os.path.join(
local,
"Google",
"Chrome",
"User Data"
)
if os.path.exists(chrome):
for profile in self.find_browser_profiles(chrome):
paths.append((
"Chrome cache",
os.path.join(profile, "Cache")
))
paths.append((
"Chrome code cache",
os.path.join(profile, "Code Cache")
))
edge = os.path.join(
local,
"Microsoft",
"Edge",
"User Data"
)
if os.path.exists(edge):
for profile in self.find_browser_profiles(edge):
paths.append((
"Edge cache",
os.path.join(profile, "Cache")
))
paths.append((
"Edge code cache",
os.path.join(profile, "Code Cache")
))
firefox = os.path.join(
os.environ.get("APPDATA", ""),
"Mozilla",
"Firefox",
"Profiles"
)
if os.path.exists(firefox):
try:
for profile in os.listdir(firefox):
paths.append((
"Firefox cache",
os.path.join(
firefox,
profile,
"cache2"
)
))
except PermissionError:
pass
return paths
def find_browser_profiles(self, browser_path):
profiles = []
try:
for item in os.listdir(browser_path):
path = os.path.join(browser_path, item)
if not os.path.isdir(path):
continue
if item == "Default" or item.startswith("Profile "):
profiles.append(path)
except PermissionError:
pass
return profiles
def get_size(self, path):
if not os.path.exists(path):
return 0
if os.path.isfile(path):
try:
return os.path.getsize(path)
except OSError:
return 0
total = 0
for root, dirs, files in os.walk(path):
for filename in files:
file_path = os.path.join(root, filename)
try:
total += os.path.getsize(file_path)
except (PermissionError, FileNotFoundError, OSError):
continue
return total
def format_size(self, size):
units = ["B", "KB", "MB", "GB", "TB"]
value = float(size)
for unit in units:
if value < 1024:
return f"{value:.2f} {unit}"
value /= 1024
return f"{value:.2f} PB"
def log(self, message):
def update():
self.results.config(state="normal")
self.results.insert("end", message + "\n")
self.results.see("end")
self.results.config(state="disabled")
self.root.after(0, update)
def start_scan(self):
if self.scanning:
return
self.scanning = True
self.total_found = 0
self.scan_button.config(state="disabled")
self.clean_button.config(state="disabled")
self.results.config(state="normal")
self.results.delete("1.0", "end")
self.results.config(state="disabled")
self.progress.config(mode="indeterminate")
self.progress.start(10)
self.status_var.set("Scanning your PC...")
threading.Thread(
target=self.scan,
daemon=True
).start()
def scan(self):
try:
paths = self.get_cleanup_paths()
total = 0
for name, path in paths:
self.log(f"Scanning: {name}")
if not os.path.exists(path):
continue
size = self.get_size(path)
total += size
self.log(f" {self.format_size(size)}")
self.total_found = total
self.root.after(0, self.scan_finished)
except Exception as error:
self.root.after(
0,
self.scan_failed,
str(error)
)
def scan_finished(self):
self.progress.stop()
self.progress.config(mode="determinate")
self.progress["value"] = 100
self.scanning = False
self.scan_button.config(state="normal")
self.clean_button.config(state="normal")
self.status_var.set("Scan complete.")
self.log("")
self.log("----------------------------------------")
self.log("Potential space to clean:")
self.log(self.format_size(self.total_found))
def scan_failed(self, error):
self.progress.stop()
self.scanning = False
self.scan_button.config(state="normal")
self.status_var.set("Scan failed.")
messagebox.showerror(
"Scan error",
error
)
def start_clean(self):
if self.cleaning:
return
if self.total_found <= 0:
messagebox.showinfo(
"Nothing to clean",
"No removable temporary data was found."
)
return
answer = messagebox.askyesno(
"Confirm cleanup",
"The cleaner will remove temporary files and browser "
"cache files.\n\n"
"Personal documents, photos, videos and downloads "
"will not be deleted.\n\n"
"Continue?"
)
if not answer:
return
self.cleaning = True
self.clean_button.config(state="disabled")
self.scan_button.config(state="disabled")
self.progress.config(mode="indeterminate")
self.progress.start(10)
self.status_var.set("Cleaning PC...")
threading.Thread(
target=self.clean,
daemon=True
).start()
def clean(self):
deleted = 0
for name, path in self.get_cleanup_paths():
self.log(f"Cleaning: {name}")
if not os.path.exists(path):
continue
deleted += self.clean_directory(path)
if self.recycle_var.get():
self.clean_recycle_bin()
self.total_deleted = deleted
self.root.after(
0,
self.clean_finished
)
def clean_directory(self, path):
deleted = 0
try:
items = os.listdir(path)
except (PermissionError, FileNotFoundError, OSError):
return 0
for item in items:
full_path = os.path.join(path, item)
try:
if os.path.isfile(full_path) or os.path.islink(full_path):
size = os.path.getsize(full_path)
os.remove(full_path)
deleted += size
elif os.path.isdir(full_path):
size = self.get_size(full_path)
shutil.rmtree(full_path)
deleted += size
except (PermissionError, FileNotFoundError, OSError):
self.log(f"Skipped: {item}")
return deleted
def clean_recycle_bin(self):
self.log("Cleaning Recycle Bin...")
try:
result = subprocess.run(
[
"powershell",
"-NoProfile",
"-Command",
"Clear-RecycleBin -Force"
],
capture_output=True,
text=True
)
if result.returncode == 0:
self.log("Recycle Bin cleaned.")
else:
self.log("Could not clean Recycle Bin.")
except Exception as error:
self.log(f"Could not clean Recycle Bin: {error}")
def clean_finished(self):
self.progress.stop()
self.progress.config(mode="determinate")
self.progress["value"] = 100
self.cleaning = False
self.scan_button.config(state="normal")
self.clean_button.config(state="normal")
self.status_var.set("Cleanup complete.")
self.log("")
self.log("----------------------------------------")
self.log("Space cleaned:")
self.log(self.format_size(self.total_deleted))
messagebox.showinfo(
"Cleanup complete",
"PC cleanup has finished.\n\n"
f"Space cleaned: {self.format_size(self.total_deleted)}"
)
def main():
root = tk.Tk()
try:
ttk.Style().theme_use("vista")
except tk.TclError:
pass
PCCleaner(root)
root.mainloop()
if __name__ == "__main__":
main()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Comments
Post a Comment