How to find the mountpoint a file resides on?

后端 未结 8 1752
半阙折子戏
半阙折子戏 2020-12-03 17:16

For example, I\'ve got a file with the following path:

/media/my_mountpoint/path/to/file.txt

I\'ve got the whole path and want to get:

8条回答
  •  感动是毒
    2020-12-03 17:58

    import os
    
    def find_mount_point(path):
        while not os.path.ismount(path):
            path=os.path.dirname(path)
        return path
    

提交回复
热议问题