Skip to content

Instantly share code, notes, and snippets.

@h4ndzdatm0ld
Created June 4, 2020 22:00
Show Gist options
  • Save h4ndzdatm0ld/f070f326877a3f845b37f1ff4fafefe8 to your computer and use it in GitHub Desktop.
Save h4ndzdatm0ld/f070f326877a3f845b37f1ff4fafefe8 to your computer and use it in GitHub Desktop.
backup
def csvbackup(REGEX, FOLDER):
""" Find any file with the REGEX pattern in the PWD
and send it to assigned FOLDER.
"""
try:
current = os.getcwd()
files = glob.iglob(os.path.join(current, REGEX))
DST_FLD = current + '/' + FOLDER
for bkup in files:
if os.path.isfile(bkup):
shutil.move(bkup, DST_FLD)
except Exception as e:
# print(e)
os.rename(bkup, (f"{bkup}-old.csv"))
csvbackup("*old.csv", FOLDER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment