Skip to content

Instantly share code, notes, and snippets.

@s3rgeym
Created July 16, 2024 21:56
Show Gist options
  • Save s3rgeym/28a6ecbdee0a00ac5217a434d0db4597 to your computer and use it in GitHub Desktop.
Save s3rgeym/28a6ecbdee0a00ac5217a434d0db4597 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pathlib
import re
directories = []
for file in pathlib.Path("./output").glob("**/*"):
if file.is_dir():
directories.append(file)
if not file.is_file():
continue
with file.open("rb") as fp:
content = fp.read(100).decode(errors="ignore")
if re.search(r"\s*<(\!doctype|html|body)", content, re.IGNORECASE):
file.unlink()
print("html file deteled:", file)
d: pathlib.Path
for d in reversed(directories):
try:
d.rmdir()
print("empty directory deleted:", d)
except OSError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment