Jump to content
Sign in to follow this  

Progress Bar for DirGetSize

Recommended Posts


My program is working great, but I wanted to add a progress bar while the DirGetSize command searches for directories. The problem is my users are opening the script and are thinking that it doesn't work while the program creates a list of Dirs. If I had a progress bar to tell them how far the scan is, then they would realise that it is working.

So this is what I have so far:

ProgressOn("Scanning Z Drive", "Please wait for the utility to open", "0 percent")
For $i = 10 to 100 step 10
    ProgressSet( $i, $i& " percent")
ProgressSet(100 , "Done", "Complete")

Is does bring up a progress bar, but it only works by the time I have set. I have found numerous ways of doing this with file transfers, but I've not found any info on getting the progress bar working for my needs, which is to estimate the time discovering the directories.

If it's not possible then this will do. I'd probably actually just put in a message box asking the users to wait before the main script starts.

Any help is appreciated. Thanks.

Here is my entire script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=Z Drive Size - Students.exe
#AutoIt3Wrapper_Res_Description=Z: Drive disk space utility
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>


Func _Main()

    Global $Input_FreeSpace, $Input_UsedSpace, $Input_DriveSize
    #Region ### START Koda GUI section ### Form=e:\software\koda\forms\tcaps control panel.kxf
    Global $MainForm = GUICreate("Z: Drive Utility", 630, 540)
    Global $FileMenu = GUICtrlCreateMenu("&File")
    Global $ExitMenu = GUICtrlCreateMenuItem("&Exit", $FileMenu)
    Global $NetDriveMenu = GUICtrlCreateMenu("&Network Drives")
    Global $MapZDrive = GUICtrlCreateMenuItem("Map &Z: Drive", $NetDriveMenu)
    Global $HelpMenu = GUICtrlCreateMenu("&Help")
    Global $AboutMenu = GUICtrlCreateMenuItem("About", $HelpMenu)

ProgressOn("Scanning Z Drive", "Please wait for the utility to open", "0 percent")
For $i = 10 to 100 step 10
    ProgressSet( $i, $i& " percent")
ProgressSet(100 , "Done", "Complete")

    GUICtrlCreateLabel("Z: Drive size", 10, 75)
    GUICtrlCreateLabel("Z: Used Space", 10, 105)
    GUICtrlCreateLabel("Z: Free Space", 10, 135)
    GUICtrlCreateLabel("MB", 159, 78)
    GUICtrlCreateLabel("MB", 159, 108)
    GUICtrlCreateLabel("MB", 159, 138)

    $Input_DriveSize = GUICtrlCreateInput("100", 120, 75, 35)

    $USED = DirGetSize("Z:\")
    $Input_UsedSpace = GUICtrlCreateInput("" & Round($USED / 1024 / 1024), 120, 105, 35)

    $FREE = 100
    $Input_FreeSpace = GUICtrlCreateInput("" & Round($FREE - $USED / 1024 / 1024), 120, 135, 35)

    $Pic1 = GUICtrlCreatePic("\\app2\k-12$\logo.bmp", 365, 45, 0, 0)

    Global $directory, $hListView, $FileList, $DirList, $Dir_Name, $Dir_size, $Dir_t, $Dir_time, $item, $File_Name, $File_size, $File_t, $File_time
    $directory = "Z:\"
    $FileList = _FileListToArray($directory, '*.*', 1) ; Only files
    $DirList = _FileListToArray($directory, '*.*', 2) ; Only directories

    $listview = GUICtrlCreateListView("File Name                                               |Size (MB)         |creation Time (YYYY/MM/DD HH:MM:SS             ", 10, 200, 615, 300)
    For $n = 1 To UBound($DirList) - 1
        $Dir_Name = $DirList[$n]
        $Dir_size = DirGetSize($directory & "\" & $Dir_Name, 0)
        $Dir_t = FileGetTime($directory & "\" & $Dir_Name, 1)
        $Dir_time = $Dir_t[0] & "/" & $Dir_t[1] & "/" & $Dir_t[2] & " " & $Dir_t[3] & ":" & $Dir_t[4] & ":" & $Dir_t[5]
        $item = GUICtrlCreateListViewItem($Dir_Name & "|" & Round($Dir_size / 1024 / 1024, 2) & "|" & $Dir_time, $listview)
        GUICtrlSetImage($item, "shell32.dll", 4)
    ; Files
    For $n = 1 To UBound($FileList) - 1
        $File_Name = $FileList[$n]
        $File_size = FileGetSize($directory & "\" & $File_Name)
        $File_t = FileGetTime($directory & "\" & $File_Name, 1) ; creation Time
        $File_time = $File_t[0] & "/" & $File_t[1] & "/" & $File_t[2] & " " & $File_t[3] & ":" & $File_t[4] & ":" & $File_t[5]
        $item = GUICtrlCreateListViewItem($File_Name & "|" & Round($File_size / 1024 / 1024, 2) & "|" & $File_time, $listview)
        If GUICtrlSetImage(-1, $directory & "\" & $File_Name, 1) = 0 Then ; If a default icon cannot be found
            ; the default icon of the file should be set here
            GUICtrlSetImage($item, "shell32.dll", 1)

        If Number(GUICtrlRead($Input_UsedSpace)) >= 100 Then
            GUICtrlCreateLabel("You have exceeded the quota limit set for your Z drive", 10, 15, 400)
            GUICtrlSetColor(-1, 0xff0000)
            GUICtrlSetFont(-1, 11.5, 600)
            GUICtrlCreateLabel("You are within the quota limit set for your Z drive", 10, 15, 400)
            GUICtrlSetColor(-1, 0x0000ff)
            GUICtrlSetFont(-1, 11.5, 600)


    #EndRegion ### END Koda GUI section ###


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
            Case $MapZDrive
                DriveMapAdd("Z:", @HomeShare, 1)
                MsgBox(0, "Successful", "The Z: Drive is now mapped")
            Case $ExitMenu
            Case $AboutMenu
                MsgBox(0, "About - Z Drive Utility", "Version 1.2")
            Case $listview
                _GUICtrlListView_SortItems($listview, GUICtrlGetState($listview))

EndFunc   ;==>_Main

Share this post

Link to post
Share on other sites


I cannot help with timing your DirGetSize, but I can offer a "marquee" progress bar that at least shows something is happening:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>

$hGUI = GUICreate("Test", 500, 500)
GUICtrlCreateProgress(10, 10, 400, 20, $PBS_MARQUEE)
_SendMessage(GUICtrlGetHandle(-1), $PBM_SETMARQUEE, True, 50) ; final parameter is update time in ms

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

I hope that helps. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

You could also use a simple splash window with either SplashTextOn() or SplashImageOn() and if memory serves correctly I have used SplashImageOn() with an animated gif.

Edit: memory is lousy. It doesn't work with an animated gif but you could create your own window to display an avi file instead of SplashImageOn.

Edited by GEOSoft


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.