本站改版新增arduino频道
import os
def _mk_dirs(path:str):
paths = path.split('/')
pathToCreate = ''
for x in paths:
mkdir(pathToCreate + x)
pathToCreate = pathToCreate + x + '/'
# different micropython versions act differently when directory already exists
def mkdir(path:str):
try:
os.mkdir(path)
except OSError as exc:
if exc.args[0] == 17:
pass
def _exists_dir(path) -> bool:
try:
os.listdir(path)
return True
except:
return False
def _copy_directory( fromPath, toPath):
if not _exists_dir(toPath):
_mk_dirs(toPath)
for entry in os.ilistdir(fromPath):
is_dir = entry[1] == 0x4000
if is_dir:
_copy_directory(fromPath + '/' + entry[0], toPath + '/' + entry[0])
else:
_copy_file(fromPath + '/' + entry[0], toPath + '/' + entry[0])
def _copy_file(fromPath, toPath):
with open(fromPath) as fromFile:
with open(toPath, 'w') as toFile:
CHUNK_SIZE = 512 # bytes
data = fromFile.read(CHUNK_SIZE)
while data:
toFile.write(data)
data = fromFile.read(CHUNK_SIZE)
toFile.close()
_copy_directory("app", "app123")
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0094399452209473 seconds