[英]How can I enumerate filesystems from Python?
我正在使用os.statvfs
來查找卷上的可用空間 - 除了查詢特定路徑的可用空間外,我還希望能夠遍歷所有卷。 我目前正在Linux上工作,但理想情況下想在Linux上返回["/", "/boot", "home"]
在Windows上返回["C:\\", "D:\\"]
。
對於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,我發現了這樣的事情:
import string
from ctypes import windll
def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
if bitmask & 1:
drives.append(letter)
bitmask >>= 1
return drives
if __name__ == '__main__':
print get_drives()
還有這個:
from win32com.client import Dispatch
fso = Dispatch('scripting.filesystemobject')
for i in fso.Drives :
print i
嘗試那些,也許他們會幫助。
這也應該有幫助: 有沒有辦法列出python中所有可用的驅動器號?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.