List all files and subdirectories in a directory. If the directory is not specified, suggest root directory, user directory, current and parent directory. :param root_dir: string: directory to list :return: list
(root_dir: str)
| 67 | |
| 68 | |
| 69 | def suggest_path(root_dir: str) -> list[str]: |
| 70 | """List all files and subdirectories in a directory. |
| 71 | |
| 72 | If the directory is not specified, suggest root directory, |
| 73 | user directory, current and parent directory. |
| 74 | |
| 75 | :param root_dir: string: directory to list |
| 76 | :return: list |
| 77 | |
| 78 | """ |
| 79 | if not root_dir: |
| 80 | return [ |
| 81 | os.path.abspath(os.sep), |
| 82 | "~", |
| 83 | os.curdir, |
| 84 | os.pardir, |
| 85 | *list_path(os.curdir), |
| 86 | ] |
| 87 | |
| 88 | if root_dir[0] not in ('/', '~') and root_dir[0:1] != './': |
| 89 | return list_path(os.curdir) |
| 90 | |
| 91 | if "~" in root_dir: |
| 92 | root_dir = os.path.expanduser(root_dir) |
| 93 | |
| 94 | if not os.path.exists(root_dir): |
| 95 | root_dir, _ = os.path.split(root_dir) |
| 96 | |
| 97 | return list_path(root_dir) |
| 98 | |
| 99 | |
| 100 | def dir_path_exists(path: str) -> bool: |
no test coverage detected