Skip to content

Commit

Permalink
Function to easily convert relative to abs path
Browse files Browse the repository at this point in the history
  • Loading branch information
SanchitMinocha committed Feb 9, 2024
1 parent 3a8932e commit 655822c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/rat/toolbox/MiscUtil.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 655822c

Please sign in to comment.