summaryrefslogtreecommitdiff
path: root/file_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'file_utils.py')
-rw-r--r--file_utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/file_utils.py b/file_utils.py
index 7a64f9f..b7cd6bc 100644
--- a/file_utils.py
+++ b/file_utils.py
@@ -92,6 +92,23 @@ def remove(path: str) -> None:
os.remove(path)
+def fix_multiple_slashes(path: str) -> str:
+ """Fixes multi-slashes in paths or path-like strings
+
+ Args:
+ path: the path in which to remove multiple slashes
+
+ >>> p = '/usr/local//etc/rc.d///file.txt'
+ >>> fix_multiple_slashes(p)
+ '/usr/local/etc/rc.d/file.txt'
+
+ >>> p = 'this is a test'
+ >>> fix_multiple_slashes(p) == p
+ True
+ """
+ return re.sub(r'/+', '/', path)
+
+
def delete(path: str) -> None:
"""This is a convenience for my dumb ass who can't remember os.remove
sometimes.