mirror of
https://github.com/Xevion/sharex-quickzoom.git
synced 2026-01-31 06:25:58 -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 = [
|
||||
'clean.py',
|
||||
'main.py',
|
||||
@@ -12,15 +11,33 @@ blacklist = [
|
||||
'.gitignore',
|
||||
]
|
||||
|
||||
def run(recycle=True, print_ignores=False):
|
||||
"""Main driver function for recycling unneeded files from the folder.
|
||||
|
||||
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('DELETED SEQUENCE STARTED')
|
||||
|
||||
print('Deletion sequence started')
|
||||
for file in os.listdir(basepath):
|
||||
filepath = os.path.join(basepath, file)
|
||||
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)
|
||||
else:
|
||||
pass
|
||||
# print('IGNORED: \'{}\''.format(filepath))
|
||||
print('\n'.join(_log))
|
||||
print(f'FINISHED DELETED {len(_log)} FILES')
|
||||
if print_ignores:
|
||||
_log.append('IGNORED: \'{}\''.format(filepath))
|
||||
print('\n'.join(_log), end='\n' if _log else '')
|
||||
print(f'Finished deleting {len(_log)} files')
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
Reference in New Issue
Block a user