如何从Python枚举文件系统?

2024-05-19 13:09:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用os.statvfs查找卷上的可用空间——除了查询特定路径的可用空间之外,我希望能够遍历所有卷。我目前正在研究Linux,但理想情况下我希望在Linux上返回["/", "/boot", "home"],在Windows上返回{}。在


Tags: 路径homeoslinuxwindows空间情况boot
1条回答
网友
1楼 · 发布于 2024-05-19 13:09:39

对于Linux,解析/etc/mtab/proc/mounts如何?或者:

import commands

mount = commands.getoutput('mount -v')
lines = mount.split('\n')
points = map(lambda line: line.split()[2], lines)

print points

对于Windows,我发现了如下内容:

^{pr2}$

还有这个:

from win32com.client import Dispatch
fso = Dispatch('scripting.filesystemobject')
for i in fso.Drives :
    print i

试试这些,也许它们能帮上忙。在

这也有助于:Is there a way to list all the available drive letters in python?

相关问题 更多 >