nimdasys Posted May 12, 2015 Share Posted May 12, 2015 (edited) 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 May 13, 2015 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 13, 2015 Moderators Share Posted May 13, 2015 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
llewxam Posted May 13, 2015 Share Posted May 13, 2015 (edited) 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 ;==>__UpdateIan Edited May 13, 2015 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. Link to comment Share on other sites More sharing options...
nimdasys Posted May 15, 2015 Author Share Posted May 15, 2015 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.M23Sorry 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 ;==>__UpdateIan Thanks for the suggestion, its much appreciated! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now