0

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")
Dominique
  • 16,450
  • 15
  • 56
  • 112
  • It looks like you only care about Windows, in which case the proposed duplicate has several answers for you. Answers for other operating systems will be different; Unix-like OSs don't have drive letters at all, for starters. If you need a solution for something more than Windows, please [edit] your question to clarify that. – Daniel Pryden Jan 07 '19 at 05:41

1 Answers1

0

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.

Dominique
  • 16,450
  • 15
  • 56
  • 112