You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.0 KiB
30 lines
1.0 KiB
|
2 days ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""Remove empty-shell dirs under docs repo: dirs whose only file is folder.bru."""
|
||
|
|
import os
|
||
|
|
DOCS = r'E:\code\crm-api-docs'
|
||
|
|
OUT = r'e:\code\crm-backend-matt\.scratch\customer-rework\clean-dirs.txt'
|
||
|
|
|
||
|
|
removed, kept = [], []
|
||
|
|
for root, dirs, files in os.walk(DOCS, topdown=False):
|
||
|
|
dirs[:] = [d for d in dirs if d not in ('.git',)]
|
||
|
|
rel = os.path.relpath(root, DOCS)
|
||
|
|
if rel == '.' or rel.startswith('environments'):
|
||
|
|
continue
|
||
|
|
entries = os.listdir(root)
|
||
|
|
if not entries:
|
||
|
|
os.rmdir(root)
|
||
|
|
removed.append(rel + ' (empty)')
|
||
|
|
elif entries == ['folder.bru']:
|
||
|
|
os.remove(os.path.join(root, 'folder.bru'))
|
||
|
|
os.rmdir(root)
|
||
|
|
removed.append(rel + ' (folder.bru only)')
|
||
|
|
elif 'folder.bru' in entries and len(entries) == 1:
|
||
|
|
pass
|
||
|
|
else:
|
||
|
|
# dir still has real content; leave it
|
||
|
|
pass
|
||
|
|
|
||
|
|
open(OUT, 'w', encoding='utf-8').write(
|
||
|
|
'REMOVED %d:\n' % len(removed) + '\n'.join(' ' + r for r in removed))
|
||
|
|
print('removed dirs:', len(removed))
|