Skip to content

Commit 5d72550

Browse files
author
Tomas Babej
committed
utils: Add helper method to remove files
1 parent 09a43fc commit 5d72550

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

datafiles/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ def read(filename: str, *, display=False) -> str:
141141
return text
142142

143143

144+
def remove(filename_or_path: Union[str, Path]) -> None:
145+
"""Remove a given file, if it exists."""
146+
filepath = Path(filename_or_path)
147+
if filepath.exists():
148+
filepath.unlink()
149+
log.debug("Removed filepath: %s", str(filepath))
150+
151+
144152
def display(path: Path, data: Dict) -> None:
145153
"""Display data read from a file."""
146154
message = f"Data from file: {path}"

0 commit comments

Comments
 (0)