Add copy_file() function to wk.io
This commit is contained in:
parent
0725674a3b
commit
aa0e35cbaa
1 changed files with 11 additions and 0 deletions
|
|
@ -61,6 +61,17 @@ def case_insensitive_search(path, item):
|
||||||
return real_path
|
return real_path
|
||||||
|
|
||||||
|
|
||||||
|
def copy_file(source, dest, overwrite=False):
|
||||||
|
"""Copy file and optionally overwrite the destination."""
|
||||||
|
source = case_insensitive_path(source)
|
||||||
|
dest = pathlib.Path(dest).resolve()
|
||||||
|
if dest.exists():
|
||||||
|
if not overwrite:
|
||||||
|
raise FileExistsError(f'Refusing to delete file: {dest}')
|
||||||
|
os.remove(dest)
|
||||||
|
shutil.copy2(source, dest)
|
||||||
|
|
||||||
|
|
||||||
def delete_empty_folders(path):
|
def delete_empty_folders(path):
|
||||||
"""Recursively delete all empty folders in path."""
|
"""Recursively delete all empty folders in path."""
|
||||||
LOG.debug('path: %s', path)
|
LOG.debug('path: %s', path)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue