Skip to content

Instantly share code, notes, and snippets.

@hiiwave
Created March 23, 2022 12:51
Show Gist options
  • Save hiiwave/79a7d0173047eba8c4fa6fcf6a6ca4a9 to your computer and use it in GitHub Desktop.
Save hiiwave/79a7d0173047eba8c4fa6fcf6a6ca4a9 to your computer and use it in GitHub Desktop.
Delete json files generated by google drive after batch download
from pathlib import Path
from tqdm.auto import tqdm
import json
def delete_google_drive_json_recursively(drive_path):
drive_path = Path(drive_path)
for f in (pbar := tqdm(drive_path.glob("**/*.json"))):
try:
data = json.loads(f.read_bytes())
except (json.JSONDecodeError, RecursionError) as e:
# print(e)
continue
else:
# Note: Might not be 100% safe, use with your caution
if not ("viewers_can_download" in data and "last_modified_by_me" in data):
continue
pbar.set_description("Removing %s" % f)
f.unlink()
# delete_google_drive_json_recursively(r"Z:/Cloud")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment