diff --git a/src/pathnavigator/folder.py b/src/pathnavigator/folder.py index 38034ae..9acfca8 100644 --- a/src/pathnavigator/folder.py +++ b/src/pathnavigator/folder.py @@ -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 ------- @@ -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.