mirror of
https://github.com/Xevion/sharex-quickzoom.git
synced 2026-01-31 08:25:54 -06:00
move into proper function, add recycle capability
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import os, sys
|
import os, sys, send2trash
|
||||||
|
|
||||||
basepath = sys.path[0]
|
|
||||||
blacklist = [
|
blacklist = [
|
||||||
'clean.py',
|
'clean.py',
|
||||||
'main.py',
|
'main.py',
|
||||||
@@ -12,15 +11,33 @@ blacklist = [
|
|||||||
'.gitignore',
|
'.gitignore',
|
||||||
]
|
]
|
||||||
|
|
||||||
_log = []
|
def run(recycle=True, print_ignores=False):
|
||||||
print('DELETED SEQUENCE STARTED')
|
"""Main driver function for recycling unneeded files from the folder.
|
||||||
for file in os.listdir(basepath):
|
|
||||||
|
Keyword Arguments:
|
||||||
|
recycle {bool} -- True to recycle and send to recycle bin instead of permanently delete a file. (default: {True})
|
||||||
|
print_ignores {bool} -- True to print what files have been ignored (default: {False})
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
basepath = sys.path[0]
|
||||||
|
_log = []
|
||||||
|
|
||||||
|
print('Deletion sequence started')
|
||||||
|
for file in os.listdir(basepath):
|
||||||
filepath = os.path.join(basepath, file)
|
filepath = os.path.join(basepath, file)
|
||||||
if file not in blacklist:
|
if file not in blacklist:
|
||||||
_log.append('DELETED: \'{}\''.format(filepath))
|
_log.append('Recycled: \'{}\''.format(filepath))
|
||||||
|
# Send to recycle bin vs straightup permanently delete
|
||||||
|
if recycle:
|
||||||
|
send2trash.send2trash(filepath)
|
||||||
|
else:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
else:
|
else:
|
||||||
pass
|
if print_ignores:
|
||||||
# print('IGNORED: \'{}\''.format(filepath))
|
_log.append('IGNORED: \'{}\''.format(filepath))
|
||||||
print('\n'.join(_log))
|
print('\n'.join(_log), end='\n' if _log else '')
|
||||||
print(f'FINISHED DELETED {len(_log)} FILES')
|
print(f'Finished deleting {len(_log)} files')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
Reference in New Issue
Block a user