How can I extract the folder path from file path in Python?

Опубликовано: 04 Август 2026
на канале: The Python Oracle
14
0

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Quirky Dreamscape Looping

--

Chapters
00:00 Question
01:01 Accepted answer (Score 208)
01:54 Answer 2 (Score 124)
02:59 Answer 3 (Score 73)
03:15 Answer 4 (Score 5)
03:30 Thank you

--

Full question
https://stackoverflow.com/questions/1...

Answer 1 links:
[pathlib]: https://docs.python.org/3/library/pat...
[available on PyPI]: https://pypi.python.org/pypi/pathlib/
[os.path]: http://docs.python.org/2/library/os.p...

Answer 2 links:
[os.path]: http://docs.python.org/2/library/os.p...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/l...

--

Tags
#python #file #path #directory #extract

#avk47