Skip to content

Commit

Permalink
add get_path_str
Browse files Browse the repository at this point in the history
  • Loading branch information
philip928lin committed Nov 1, 2024
1 parent 48d0ea1 commit d138465
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/pathnavigator/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,30 @@ def get(self, filename: str = None) -> str:
print(f"'{filename}' not found in '{self.get()}'")
return None
return self.files[valid_name]


def get_path_str(self, filename: str = None) -> str:
"""
Get the full path of a file in the current folder as a string.
Parameters
----------
filename : str
The name of the file to get. If None, returns the full path of the folder.
Default is None. If the file does not exist, returns None.
Returns
-------
str
The full path to the file as a string.
Examples
--------
>>> folder = Folder(name="root")
>>> folder.get_path_str("file1")
'/home/user/root/file1'
"""
return str(self.get(filename))

def chdir(self):
"""
Set this directory as working directory.
Expand Down

0 comments on commit d138465

Please sign in to comment.