OS Path Module
Published Jun 25, 2022
Contribute to Docs
The os.path
module supports operations on pathnames, which can be passed as strings or bytes. The functions under os.path
differ from the ones under the glob
module in that they are used for working with and creating specific paths (rather than just filtering through them under certain criteria).
OS Path Module
- .basename()
- Returns the part of a pathname after the last forward-slash.
- .dirname()
- Returns the part of the pathname ranging from the start to the last forward-slash.
- .exists()
- Checks whether a given file or folder exists in the directory of an operating system.
- .join()
- Returns a string of pathnames delimited with a forward-slash.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours