是否有pythonic方式并且没有shell命令(即使用子进程模块)来检查目录是否是挂载点?
到目前为止我使用:
import os
import subprocess
def is_mount_point(dir_path):
try:
check_output([
'mountpoint',
path.realpath(dir_name)
])
return True
except CalledProcessError:
return False
Run Code Online (Sandbox Code Playgroud)
Łuk*_*ski 14
如果路径名路径是装入点,则返回True:文件系统中已装入其他文件系统的点.该函数检查路径的父路径,路径/ ..是否在与路径不同的设备上,或路径/ ..和路径是否指向同一设备上的同一个i节点 - 这应检测所有Unix和POSIX的安装点变种.
import os
os.path.ismount(dir_name) # returns boolean
Run Code Online (Sandbox Code Playgroud)
您也可以参考实现(如果您使用的是POSIX系统).检查macpath.py或ntpath.py其他平台.
在 Python 3.7 中,使用 Path.is_mount()
>>> from pathlib import Path
>>> p = Path('/some/mounted/dir/')
>>> p.is_mount()
True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6293 次 |
| 最近记录: |