Return the file name that `file_path` refers to, optionally removing the extension. E.g. /tmp/foo.bar -> foo
(file_path: StrPath, include_extension: bool = True)
| 127 | |
| 128 | |
| 129 | def get_file_name(file_path: StrPath, include_extension: bool = True) -> str: |
| 130 | """Return the file name that `file_path` refers to, optionally removing the extension. |
| 131 | |
| 132 | E.g. /tmp/foo.bar -> foo""" |
| 133 | file_name = os.path.basename(os.fspath(file_path)) |
| 134 | if not include_extension: |
| 135 | last_dot_pos = file_name.rfind(".") |
| 136 | if last_dot_pos >= 0: |
| 137 | file_name = file_name[:last_dot_pos] |
| 138 | return file_name |
| 139 | |
| 140 | |
| 141 | def get_and_create_path(file_path: StrPath, output_directory: StrPath | None = None) -> str: |