I need a script which would show me how much of free space I have on C:\ disk. What is the best way to do that? I am working with Python 3.6. Thank you in advance :)
Asked
Active
Viewed 420 times
1
-
2What if a second disk is mounted in a directory of C:\? – Willem Van Onsem Oct 10 '18 at 11:45
-
I did not think about that... I am going to use this script to check the space of several disks and I gave C:\ as an example. I guess they won''t have any other disks mounted in their directory – Slowflake Oct 10 '18 at 11:48
1 Answers
1
You could use the os
library in python to execute shell commands. For windows, command to check directory usage is fsutil volume diskfree c:
so you could do something like:
import os
command = "fsutil volume diskfree c:"
os.system(command)
Hope this works! The output should be something like:
Total # of free bytes : 145709916160
Total # of bytes : 254930841600
Total # of avail free bytes : 145709916160

Saket Kumar Singh
- 642
- 6
- 13
-
This for sure works _somehow_ but are we really in need to create a separate bash process through **Linux on Windows** only to check what is the space left? Also, you did not provide any parsing of the result. At most partial and suboptimal solution! – sophros Oct 10 '18 at 11:52
-
I edited my answer for the corresponding Windows command. I had mistakenly skipped the part where the question mentions C:\ disk. Also including the output. – Saket Kumar Singh Oct 10 '18 at 11:55
-
Even though the answer was accepted I still think it is a bad code. Unnecessarily spawning a separate process when what would be needed on the Python side is just to invoke an appropriate API call. – sophros Oct 10 '18 at 12:24
-
I accepted this answer because it worked for my specific problem. I also agree that I wasn't the firs to ask this question so the link of the original question is seen in the top. Anyone who has the same problem as mine could try this answer and if this does not work (or if there is a need of some different solution), there are a lot of different ways suggested in the link of the original question. – Slowflake Oct 10 '18 at 12:36