Select Git revision
delete_old_files.py.j2

Robin Sonnabend authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
delete_old_files.py.j2 1019 B
#!/usr/bin/env python3
# taken from https://www.dokuwiki.org/install:unused_files
# under CC BY-SA 4.0 International https://creativecommons.org/licenses/by-sa/4.0/deed.en
# for authors see https://www.dokuwiki.org/install:unused_files?do=revisions
import os
import os.path
import shutil
def exists_casesensitive(path):
if not os.path.exists(path):
return False
directory, filename = os.path.split(path)
return filename in os.listdir(directory)
cwd = os.getcwd()
os.chdir("{{ item.path }}")
with open("{{ item.path }}/data/deleted.files") as file:
for line in file:
line = line.strip()
if line and not line.startswith('#'):
path = line.rstrip(os.linesep)
if exists_casesensitive(path):
if os.path.isdir(path):
shutil.rmtree(path)
print('Directory removed => ' + path)
else:
os.remove(path)
print('File removed => ' + path)
os.chdir(cwd)