Jump to content
nimdasys

Update label as each file is being deleted

Recommended Posts

nimdasys

I have a script with a GUI that deletes temporary files. There is a label in the GUI that shows the current file being deleted and it continuously updates to the current file being deleted. What are some other ways the code below can be written to achieve a continuously updated label?

Func TempDelete(ByRef $ProgressBar, ByRef $Status)
    Local $Temp = @TempDir & '\'
    Local $DirSize
    Local $TotalFiles= 0
    If Fileexists($Temp) Then
        $DirSize = DirGetSize($Temp, 1)
        $TotalFiles= $DirSize[1]
        $Search = FileFindFirstFile($Temp & '*')
            While 1
                $File = FileFindNextFile($Search)
                If @error or $File = '' Then ExitLoop
                GUICtrlSetData($Status, 'Deleting ' & $File)
                FileDelete($Temp & $File)
                DirRemove($Temp & $File, 1)
                $DirSize = DirGetSize($Temp , 1)
                GUICtrlSetData($ProgressBar, ($TotalFiles- $DirSize[1])/$TotalFiles * 100)
            WEnd
        GUICtrlSetData($ProgressBar, 100)
        $DirSize = DirGetSize($Temp, 1)
        Return $TotalFiles- $DirSize[1]
    EndIf
EndFunc

 

 

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites
Melba23

nimdasys,

Welcome to the AutoIt forum.

But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!".  I have moved it for you, but would ask you to be more careful in future.

M23


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

Spoiler

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
llewxam

Sorry if this is more than you bargained for..... :)

 

Every time you update the label the actual function of the script, deleting files, is stopped, plus the more quickly the label is updated, the more likely it may have some flickering.  What I have done in the past is use a Global variable for something such as a file name, and before starting a loop I call AdlibRegister for something like 250ms (.25 second) to update the label.  Updating the label 4 times a second should give more than enough information on the progress of deletes, removes any flicker in the label, and will massively improve the speed of the script.

Global $TempFileName, $Status

Func TempDelete(ByRef $ProgressBar, ByRef $Status)
    Local $Temp = @TempDir & '\'
    Local $DirSize
    Local $TotalFiles = 0
    If FileExists($Temp) Then
        $DirSize = DirGetSize($Temp, 1)
        $TotalFiles = $DirSize[1]
        $Search = FileFindFirstFile($Temp & '*')
        AdlibRegister("__Update", 250)
        While 1
            $File = FileFindNextFile($Search)
            If @error Or $File = '' Then ExitLoop
            $TempFileName = $File
            FileDelete($Temp & $File)
            DirRemove($Temp & $File, 1)
            $DirSize = DirGetSize($Temp, 1)
            GUICtrlSetData($ProgressBar, ($TotalFiles - $DirSize[1]) / $TotalFiles * 100)
        WEnd
        AdlibUnRegister()
        GUICtrlSetData($ProgressBar, 100)
        $DirSize = DirGetSize($Temp, 1)
        Return $TotalFiles - $DirSize[1]
    EndIf
EndFunc   ;==>TempDelete

Func __Update()
    GUICtrlSetData($Status, 'Deleting ' & $TempFileName)
EndFunc   ;==>__Update

Ian

Edited by llewxam

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites
nimdasys

nimdasys,

Welcome to the AutoIt forum.

But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!".  I have moved it for you, but would ask you to be more careful in future.

M23​

Sorry for posting in the wrong forum, not sure how I didn't see that at first. 

 

Sorry if this is more than you bargained for..... :)

 

Every time you update the label the actual function of the script, deleting files, is stopped, plus the more quickly the label is updated, the more likely it may have some flickering.  What I have done in the past is use a Global variable for something such as a file name, and before starting a loop I call AdlibRegister for something like 250ms (.25 second) to update the label.  Updating the label 4 times a second should give more than enough information on the progress of deletes, removes any flicker in the label, and will massively improve the speed of the script.

Global $TempFileName, $Status

Func TempDelete(ByRef $ProgressBar, ByRef $Status)
    Local $Temp = @TempDir & '\'
    Local $DirSize
    Local $TotalFiles = 0
    If FileExists($Temp) Then
        $DirSize = DirGetSize($Temp, 1)
        $TotalFiles = $DirSize[1]
        $Search = FileFindFirstFile($Temp & '*')
        AdlibRegister("__Update", 250)
        While 1
            $File = FileFindNextFile($Search)
            If @error Or $File = '' Then ExitLoop
            $TempFileName = $File
            FileDelete($Temp & $File)
            DirRemove($Temp & $File, 1)
            $DirSize = DirGetSize($Temp, 1)
            GUICtrlSetData($ProgressBar, ($TotalFiles - $DirSize[1]) / $TotalFiles * 100)
        WEnd
        AdlibUnRegister()
        GUICtrlSetData($ProgressBar, 100)
        $DirSize = DirGetSize($Temp, 1)
        Return $TotalFiles - $DirSize[1]
    EndIf
EndFunc   ;==>TempDelete

Func __Update()
    GUICtrlSetData($Status, 'Deleting ' & $TempFileName)
EndFunc   ;==>__Update

Ian

 Thanks for the suggestion, its much appreciated!

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

×

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.