Skip to content

Instantly share code, notes, and snippets.

@mintisan
Last active August 28, 2016 07:29
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 mintisan/e4ac4593c7f47f63bfc9bf23a8b85f9c to your computer and use it in GitHub Desktop.
Save mintisan/e4ac4593c7f47f63bfc9bf23a8b85f9c to your computer and use it in GitHub Desktop.
copy bin from Downloads directory to board(like Nucleo) automatically for mbed
import os
from shutil import copyfile
# `sudo pip install walkdir` if you don't install walkdir
import walkdir as wd
import time
src_dir = os.environ['HOME']+'/Downloads/'
dst_dir = '/Volumes/NUCLEO/'
pattern = "*_NUCLEO_F401RE.bin"
while True:
time.sleep(1)
bin_file = wd.file_paths(wd.filtered_walk(src_dir, depth=0,included_files=[pattern]))
fn_l = list(bin_file)
if len(fn_l) == 0:
print("no bin file is exits!")
continue
fn = str(fn_l[0]).split('/')[-1]
print(fn, "is coped to " + dst_dir)
copyfile(src_dir+fn,dst_dir+fn)
os.remove(src_dir+fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment