Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
philip928lin committed Nov 3, 2024
2 parents 87e7629 + d138465 commit 230fcad
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/pathnavigator/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,15 @@ def set_shortcut(self, name: str, filename: str = None):
else:
self._pn_object.sc.add(name, self.join(filename))

def get(self, filename: str = None):
def get(self, filename: str = None) -> str:
"""
Get the full path of a file in the current folder.
Parameters
----------
filename : str
The name of the file to get.
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
-------
Expand All @@ -289,7 +290,30 @@ def get(self, filename: str = None):
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 230fcad

Please sign in to comment.