Gets the portion of a path following the last (non-terminal) separator (`/`). Semantics align with NodeJS's `path.basename` except that we support URL's as well. If the base name has any one of the provided extensions, it is removed. // POSIX GetBaseFileName("/path/to/file.ext") == "file.ext" Ge
(path string)
| 838 | // GetBaseFileName("file:///") == "" |
| 839 | // GetBaseFileName("file://") == "" |
| 840 | func GetBaseFileName(path string) string { |
| 841 | path = NormalizeSlashes(path) |
| 842 | |
| 843 | // if the path provided is itself the root, then it has no file name. |
| 844 | rootLength := GetRootLength(path) |
| 845 | if rootLength == len(path) { |
| 846 | return "" |
| 847 | } |
| 848 | |
| 849 | // return the trailing portion of the path starting after the last (non-terminal) directory |
| 850 | // separator but not including any trailing directory separator. |
| 851 | path = RemoveTrailingDirectorySeparator(path) |
| 852 | return path[max(GetRootLength(path), strings.LastIndex(path, string(DirectorySeparator))+1):] |
| 853 | } |
| 854 | |
| 855 | // Gets the file extension for a path. |
| 856 | // If extensions are provided, gets the file extension for a path, provided it is one of the provided extensions. |