Skip to content

Instantly share code, notes, and snippets.

@theoparis
Created February 3, 2021 22:49
Show Gist options
  • Save theoparis/4a3e9cf4dac0bc0188acb965d9c39114 to your computer and use it in GitHub Desktop.
Save theoparis/4a3e9cf4dac0bc0188acb965d9c39114 to your computer and use it in GitHub Desktop.
backup file structure glob to json file

File Structure -> JSON Array

Usage

python3 main.py "root_dir" "sub_dir/*"

Example

python3 main.py "~/" "Documents/*"

from pathlib import Path
import os
import json
import sys
paths = []
for txt_path in Path(sys.argv[1]).glob(sys.argv[2]):
paths.append(os.path.basename(txt_path))
with open("data.json", "w") as write_file:
json.dump({"files": paths}, write_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment