Skip to content

Instantly share code, notes, and snippets.

@thehesiod
Last active December 6, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehesiod/c2ac231d3f3bac5a9824de9d3efedffe to your computer and use it in GitHub Desktop.
Save thehesiod/c2ac231d3f3bac5a9824de9d3efedffe to your computer and use it in GitHub Desktop.
Delete Empty Android DCIM folders
# requires webdav connection (see WebDAV Server app, and ensure port is not 8080)
from pathlib import Path
import shutil
def main():
cam_path = Path('//192.168.1.186@8081/DavWWWRoot/DCIM/Camera')
for idx, item in enumerate(cam_path.iterdir()):
if idx % 100 == 0:
print(f"Processing folder {idx}")
if not item.is_dir():
continue
try:
if not ({i.name for i in item.glob('*')} - {'.deletemarkers'}):
print(f'deleting {item}')
shutil.rmtree(item)
except BaseException as e:
print(f"Skipping {item} due to {e}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment