You can find the name of a directory in Python using the os
module or the pathlib
module. Both of these modules have functions that allow you to get information about directories.
Here is an example using os
:
main.py90 chars7 lines
This will print the name of the directory at the given path.
Here is an example using pathlib
:
main.py98 chars7 lines
This will also print the name of the directory at the given path.
gistlibby LogSnag