You can use the os.path module in Python to find the root directory of a directory. The root directory is the top level directory of the file system in which the directory resides. Here's an example:
main.py316 chars13 linesIn this example, find_root_directory takes a directory path as input and returns the root directory path using os.path.abspath and os.path.join. The os.pardir constant is used to reference the parent directory in the path.
gistlibby LogSnag