'Is there a pathlib equivalent to os.path.basename under Windows?

When running Python 3.9.5 on Windows 10:

  • Path("c:/temp/one/two/").name == "two"
  • PurePath("c:/temp/one/two/").name == "two"
  • PureWindowsPath("c:/temp/one/two/").name == "two"

while

  • os.path.basename("c:/temp/one/two/").name == ""


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source