From 655822c009a9ae3cd224ef4ee97d7d2fcfb35a76 Mon Sep 17 00:00:00 2001 From: Sanchit Minocha Date: Fri, 9 Feb 2024 06:48:36 -0800 Subject: [PATCH] Function to easily convert relative to abs path --- src/rat/toolbox/MiscUtil.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/rat/toolbox/MiscUtil.py diff --git a/src/rat/toolbox/MiscUtil.py b/src/rat/toolbox/MiscUtil.py new file mode 100644 index 00000000..0f56acd6 --- /dev/null +++ b/src/rat/toolbox/MiscUtil.py @@ -0,0 +1,24 @@ +from pathlib import Path #to work with relative paths + +## Function to convert a relative path to absolute path +def rel2abs(relative_path: str) -> str: + ''' + Convert a relative path to an absolute path. + + Parameters: + - relative_path (str): The relative path to be converted. + + Returns: + - str: The absolute path. + + Example: + ``` + relative_path = 'subfolder/file.txt' + absolute_path = rel2abs(relative_path) + ``` + ''' + # Get the absolute path + absolute_path = Path(relative_path).resolve() + + # Convert Path object to string + return str(absolute_path) \ No newline at end of file