Skip to content

Commit

Permalink
Greatly improved cleaner.py code formatting and rearranged around som…
Browse files Browse the repository at this point in the history
…e files, updated gitignore and exe file
  • Loading branch information
JordanLeich committed Jul 4, 2021
1 parent a170b1d commit 47b8d52
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Junk File Cleaner Installer.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Description :open_file_folder:
- This is used as a python script that I use for my computer. This script is set to automatically run everyday at 1:30pm, once running the script will open a pre-installed cleaning program that is on every windows PC and then open two other junk folders inside of windows to clean up. You can also [visit](https://jordanleich.github.io/Junk-File-Cleaner/) my website for additional information.

![Junk Folders](demos/demo.gif "Junk Folders")
![Junk Folders](images/demo.gif "Junk Folders")

# Important :zap:
1. You do not need python installed to be able to use my program! If you choose not to use python or don't have it installed, you can download the .exe installer and use that instead!
Expand Down
84 changes: 44 additions & 40 deletions Cleaner.py → cleaner.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Made by Jordan Leich on 6/14/2020, Last updated on 8/15/2020 IMPORTANT NOTE TO READ*** This cleaner script will
# Made by Jordan Leich on 6/14/2020, IMPORTANT NOTE TO READ*** This cleaner script will
# work best if you are an administrator on your PC. Without being an administrator, the script will only partially
# clean junk files and will eventually hit an error that will end the script.

# All imports used
import os
import shutil
import time as ti
from time import sleep
from colored import fg, attr

# Extra global Variables used
green = fg('green')
red = fg('red')
yellow = fg('yellow')
reset_color = attr('reset')


def end():
"""
End of the program when the cleaner finishes cleaning junk files
End of the program when the cleaner finishes cleaning all junk files
"""
print(green + 'Cleaning Successful!\n', reset_color)
ti.sleep(1)
sleep(1)
quit()


def second():
def first_folder_cleaner():
"""
Second folder to clean (May require administrator)
Second folder to clean (May require administrator)
"""
folder = 'C:\Windows\Temp'
ti.sleep(1)
list = os.listdir(folder)
number_files = len(list)
print(red + 'Junk files/folders found in the first folder: ', number_files, reset_color, '\n')
ti.sleep(2)
sleep(1)
directory_list = os.listdir(folder)
number_files = len(directory_list)
print(red + 'Junk files/folders found in the first folder:', number_files, reset_color, '\n')
sleep(2)

for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
Expand All @@ -44,20 +44,20 @@ def second():
shutil.rmtree(file_path)
except Exception as e:
print(red + 'Failed to delete %s. Reason: %s' % (file_path, e), '\n', reset_color)
ti.sleep(1)
third()
sleep(1)
second_folder_clean()


def third():
def second_folder_clean():
"""
Third folder to clean (Does require administrator)
Third folder to clean (Does require administrator)
"""
second_folder = 'C:\Windows\Prefetch'
ti.sleep(1)
list = os.listdir(second_folder)
number_files = len(list)
print(red + 'Junk files/folders found in the second folder: ', number_files, reset_color, '\n')
ti.sleep(2)
sleep(1)
directory_list = os.listdir(second_folder)
number_files = len(directory_list)
print(red + 'Junk files/folders found in the second folder:', number_files, reset_color, '\n')
sleep(2)

for filename in os.listdir(second_folder):
file_path = os.path.join(second_folder, filename)
Expand All @@ -69,61 +69,65 @@ def third():
shutil.rmtree(file_path)
except Exception as e:
print(red + 'Failed to delete %s. Reason: %s' % (file_path, e), '\n', reset_color)
ti.sleep(1)
sleep(1)
end()


def first():
def first_cleaner():
"""
Opens a cleaning program that is pre-installed with windows (Doesn't require administrator)
Opens a cleaning program that is pre-installed with windows (Doesn't require administrator) and then proceeds to clean
other folders
"""
clean = os.popen('cleanmgr.exe /sagerun:1').read()
print(clean)
ti.sleep(1)
second()
sleep(1)
first_folder_cleaner()


def basic_clean():
"""
Basic Clean - Opens a cleaning program that is pre-installed with windows (Doesn't require administrator)
Opens a cleaning program that is pre-installed with windows (Doesn't require administrator) and then quits the program
"""
clean = os.popen('cleanmgr.exe /sagerun:1').read()
print(clean)
ti.sleep(1)
sleep(1)
end()


def start():
def main():
"""
This is the very start of the program, the user is asked for input to choose between a basic or advanced
cleaning, or they can choose to quit the program.
This is the very start of the program, the user is asked for input to choose between a basic or advanced
cleaning, or they can choose to quit the program
"""
try:
user_choice2 = str(input('Basic clean, Advanced clean, or quit (basic, advanced, or quit): '))
print()

if user_choice2.lower() == 'basic' or user_choice2.lower() == 'b':
if user_choice2.lower() in ['basic', 'b']:
print('Basic clean running...', reset_color)
basic_clean()

elif user_choice2.lower() == 'advanced' or user_choice2.lower() == 'a':
elif user_choice2.lower() in ['advanced', 'a']:
print('Advanced clean running...', reset_color)
first()
first_cleaner()

elif user_choice2.lower() == 'quit' or user_choice2.lower() == 'q':
elif user_choice2.lower() in ['quit', 'q']:
print('Ending cleaner...')
ti.sleep(1)
sleep(1)
quit()

else:
print(red + "Invalid input... Restart input...\n", reset_color)
ti.sleep(1)
start()
sleep(1)
main()

except Exception as e:
print(red, e, '\n', reset_color)
ti.sleep(3)
sleep(2)
quit()


start() # Starts the first section of the program
main() # Starts the first section of the program

if __name__ == '__main__':
main()
Binary file removed demos/demo1.mp4
Binary file not shown.
File renamed without changes
138 changes: 138 additions & 0 deletions other/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
1 change: 1 addition & 0 deletions other/pyinstaller command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller -F -i images\icon.ico cleaner.py

0 comments on commit 47b8d52

Please sign in to comment.