'how can i find how many hdd or ssd has a computer [duplicate]
I have this case and I find the size of any file. If I don't know how many disks has my computer(for example C:,D:,Z:...or "panos:" or "name:"), how can I find this? How can I find the number of disks in a computer with python?
Are there any libraries on this topic? Also i want to run code in any operating system.
Please help.
import os
from os.path import join, getsize
for root, dirs, files in os.walk("C:"):
print(root, end=".py")
print(sum([getsize(join(root, name)) for name in files]), end="")
print("bytes in", len(files), "non-directory files")
Solution 1:[1]
If you're interested in the drives and their mappings, there's following Windows WMI command:
wmic logicaldisk list
If you're interested in the hardware, you can use following Windows WMI command:
wmic diskdrive list
Using os
library, you can launch those external commands and parse their results.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dominique |