Created
December 14, 2018 17:41
-
-
Save mobileappconsultant/7e3878910a6e0acb7d231398e27515d2 to your computer and use it in GitHub Desktop.
A very simple and basic script to delete unwanted folders of a very specific type, in this case, .dmg files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fnmatch | |
CONSTANT_DIRECTORY_TO_CLEAN = "/Users/arkangel/Downloads/" | |
os.chdir(CONSTANT_DIRECTORY_TO_CLEAN) | |
# ensure that change to that directory worked | |
print(os.getcwd()) | |
# just to get an idea of all the files in that directory | |
listOfFiles = os.listdir('.') | |
# ok, i want to find all downloaded(and installed) applications not in use Mac(.dmg) Windows(.exe) | |
pattern = "*.dmg" | |
# I expect a list, iterate | |
for entry in listOfFiles: | |
# simple find and check that a file, folder or directory matches this pattern | |
if fnmatch.fnmatch(entry, pattern): | |
# if it matches that pattern, print it | |
print(entry) | |
# print the title | |
print(entry.title()) | |
# delete it | |
os.remove(entry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment