Skip to content

Instantly share code, notes, and snippets.

@eddotman
Last active December 17, 2015 10:39
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 eddotman/5596056 to your computer and use it in GitHub Desktop.
Save eddotman/5596056 to your computer and use it in GitHub Desktop.
Copies a file repeatedly on a timed loop. Useful for saving 'snapshots' of self-updating files (e.g. configurations of Monte Carlo simulations).
from time import sleep
from shutil import copyfile
import os
def copy_loop(total_loops, interval, src_file, dst_file):
for x in range(total_loops):
f_name = dst_file + "_" + str(x)
copyfile(src_file, f_name)
sleep(interval)
return "Copying completed successfully."
output_name = "TEST"
print copy_loop(10, 3600, os.path.dirname(os.path.realpath(__file__)) + "\\" + output_name, os.path.dirname(os.path.realpath(__file__)) + "\\" + output_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment