-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFiles.py
34 lines (25 loc) · 808 Bytes
/
Files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import shutil
from pathlib import Path
def delete(path: Path) -> None:
"""
Recursively deletes `path` without confirmation.
:param path: the path to the file/directory to delete
:return: `None`
"""
if not path.exists():
return
if path.is_file():
path.unlink()
else:
shutil.rmtree(path)
def move_into(path: Path, target: Path) -> None:
"""
Moves `path` into the directory `target`, retaining the name of `path`, and creating `target` and its parents if
they do not exist yet.
:param path: the file/directory to move into `path`
:param target: the directory to move `path` into
:return: `None`
"""
target.mkdir(exist_ok=True, parents=True)
delete(target / path.name)
shutil.move(path, target / path.name)