Sign in to follow this  
Followers 0
waardd

Use diskusage function for multiple disks

5 posts in this topic

I have a function to calculate diskusage and set it on a progressbar.

$PercC = GUICtrlCreateLabel("",20,55,125,15,-1,-1)
$BarC = GUICtrlCreateProgress(20,40,200,15,-1,-1)
Func _diskC()
$FileSys = DriveGetFileSystem( "c:\" )
$SizeFree = (DriveSpaceFree( "c:\" )/1024)
$SizeTotal = (DriveSpaceTotal("c:\")/1024)
$SizeUsed = $SizeTotal - $SizeFree
$PercUsed = ($SizeUsed/$SizeTotal)*100
$PercRounded2 = StringFormat("%.2f", $PercUsed)&"% in use op C:"
GuiCtrlSetData($BarC,$PercUsed)
GuiCtrlSetData($PercC,$PercRounded2)
EndFunc

What i want is a automated routine to do this for al disks in a system independant of the configuration and show them al in on screen (kinda like explorer in windows)

Share this post


Link to post
Share on other sites



Hi waardd,

first you need to identify all hard drives in your system ... see function DriveGetDrive().

Now you know how many drives you have and what their drive letter is.

So you can 1. determine how big your GUI has to be and 2. how may labels and progress bars you'll need.

Just run your function with different parameters.

Create an array for your label/percentage gui objects.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Tnx Hannes08

I found the functions and combined it with my script to look something like this ;)

#include <GUIConstantsEx.au3>
$Form1_1 = GUICreate("DiscInfo", 615, 350, 192, 124)
$var = DriveGetDrive( "all" )
If NOT @error Then
For $i = 1 to $var[0]
  $FileSys = DriveGetFileSystem( $var[$i] )
  $SizeFree = (DriveSpaceFree( $var[$i] )/1024)
  $SizeTotal = (DriveSpaceTotal($var[$i])/1024)
  $SizeUsed = $SizeTotal - $SizeFree
  $PercUsed = ($SizeUsed/$SizeTotal)*100
  $PercRounded2 = StringFormat("%.2f", $PercUsed)
  if $PercRounded2 < 0 Then
   GUICtrlCreateLabel("Drive "&$var[$i]&" is unknown",10,$i*15, 190)
  
  Else
   GUICtrlCreateLabel("Drive "&$var[$i]&" uses "&$PercRounded2&" %",10,$i*15, 190)
   GUICtrlCreateProgress(200,$i*15,200,15,-1,-1)
   GuiCtrlSetData(-1,$PercUsed)
  EndIf
Next
EndIf
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

This is with help from example script for compinfo.au3 by

JSThePatriot

Edited by waardd

Share this post


Link to post
Share on other sites

This is what I came up with:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$a_drives = DriveGetDrive("ALL")
Global $a_guielements[$a_drives[0] + 1][2]
$a_guielements[0][0] = $a_drives[0] * 2

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 300, 40 + 20 * $a_drives[0], -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
for $i = 1 to $a_drives[0]
    $a_guielements[$i][0] = GUICtrlCreateLabel($a_drives[$i], 20, 20 * $i, 110, 17)
    $a_guielements[$i][1] = GUICtrlCreateProgress(130, 20 * $i, 150, 17)
    _disk($a_drives[$i], $a_guielements[$i][1], $a_guielements[$i][0])
Next
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

Func _disk($letter, $progress, $label)
    $FileSys = DriveGetFileSystem( $letter )
    $SizeFree = (DriveSpaceFree( $letter )/1024)
    $SizeTotal = (DriveSpaceTotal($letter)/1024)
    If $SizeTotal > 0 Then
        $SizeUsed = $SizeTotal - $SizeFree
        $PercUsed = ($SizeUsed/$SizeTotal)*100
        $PercRounded2 = StringFormat("%.2f", $PercUsed)&"% in use on " &  StringUpper($letter)
        GuiCtrlSetData($progress,$PercUsed)
        GuiCtrlSetData($label,$PercRounded2)
    Else
        GuiCtrlSetData($progress, 0)
        GuiCtrlSetData($label,StringUpper($letter) & " seems to be empty!")
    EndIf
EndFunc

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0