From aa0e35cbaa72e02fa9454f125dcad325dd729fb5 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 13 Oct 2021 17:56:47 -0600 Subject: [PATCH] Add copy_file() function to wk.io --- scripts/wk/io.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/wk/io.py b/scripts/wk/io.py index 3e2c8d04..8e398da4 100644 --- a/scripts/wk/io.py +++ b/scripts/wk/io.py @@ -61,6 +61,17 @@ def case_insensitive_search(path, item): 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): """Recursively delete all empty folders in path.""" LOG.debug('path: %s', path)