Skip to content

Instantly share code, notes, and snippets.

@jakekara
Last active January 18, 2024 20:51
Show Gist options
  • Save jakekara/662252d46afc2c9a3c7258ec51448c4c to your computer and use it in GitHub Desktop.
Save jakekara/662252d46afc2c9a3c7258ec51448c4c to your computer and use it in GitHub Desktop.
Copy dotenv files
"""Make a copy of all of my .env files in all of my projects"""
import os
import glob
import shutil
PROJECTS_DIR=os.path.expanduser("~/Projects/")
DEST_DIR = "dot_files"
try:
os.makedirs(DEST_DIR)
except:
pass
PATTERN = os.path.join(PROJECTS_DIR, "**/.*env.*")
print(f"Using pattern: '{PATTERN}'")
env_files = glob.glob(PATTERN)
for env_file in env_files:
new_path = os.path.join(DEST_DIR, env_file.replace(PROJECTS_DIR,""))
print(f"{env_file} => {new_path}")
try:
os.makedirs(os.path.split(new_path)[0])
except:
pass
shutil.copy(env_file, new_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment