Xenobiologist Posted January 28, 2012 Posted January 28, 2012 What path to you pass to the function? Which works and which not? It is dangerous to address a variable as array if you do not know if the variable really is an array. Alternative is to check If isArray($...) Then ... inside this if you can check the first element. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
johnmcloud Posted January 28, 2012 Author Posted January 28, 2012 (edited) Not work the full path, the relative path work. I can't make the size without a full path It's a simply folder using FileSelectFolder ( autoit folder in example ) I have change the line into: If IsArray($DeleteList) = 0 Then Edited January 28, 2012 by johnmcloud
johnmcloud Posted January 28, 2012 Author Posted January 28, 2012 (edited) Ok guys, i have figured out how to make full path, an error with FileGetTime So now FileGetSize work. The two problem: 1) How to have the sum of all files, with this function i have single size of single file: For $i = 1 to $DeleteList[0] $size = FileGetSize($DeleteList[$i]) MsgBox(0, "", "Size(KB):" & Round($size / 1024 )) Next 2) With subtotal, make a progress gui bar from to subtotal to 0 Thanks for support Edited January 28, 2012 by johnmcloud
czardas Posted January 28, 2012 Posted January 28, 2012 (edited) Simple: add increments within the loop. Local $iTotalSize = 0 For $i = 1 to $DeleteList[0] $iTotalSize += FileGetSize($DeleteList[$i]) Next MsgBox(0, "", "Total Size(KB): " & Round($iTotalSize / 1024 )) Try to create a progress bar and post the code if you get stuck. Edited January 28, 2012 by czardas operator64Â Â ArrayWorkshop
johnmcloud Posted January 29, 2012 Author Posted January 29, 2012 (edited) Thanks czardas, For the progressbar, i know how create it and how to set: expandcollapse popup#include <GuiConstants.au3> $Gui = GuiCreate("Progress Demo", 350, 120) $ProgressLabel = GUICtrlCreateLabel("Status: Press the button! ;) ", 20, 30, 330) $Progress = GUICtrlCreateProgress(20, 50, 300, 20) $StartButton = GUICtrlCreateButton("Start Simulation Progress", (350/2)-(140/2), 80, 140) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit Case $StartButton GUICtrlSetData($ProgressLabel, "Status: Please wait...") Dim $FilesArr[1000] For $i = 1 To UBound($FilesArr)-1 $FilesArr[$i] = _GetRandomName(6) & ".test" Next Local $FilesCount = UBound($FilesArr)-1 Local $CurrentFName, $ProgressSet = 0 GUICtrlSetData($ProgressLabel, "Status: 0% Done...") GUICtrlSetData($StartButton, "Abort Simulation Progress") For $i = 1 To $FilesCount Sleep(40) $CurrentFName = $FilesArr[$i] $ProgressSet = Round(100 / ($FilesCount / $i)) GUICtrlSetData($ProgressLabel, "Status: " & $ProgressSet & "% Done, [" & $CurrentFName & "]") GUICtrlSetData($Progress, $ProgressSet) If GUIGetMsg() = $StartButton Then ExitLoop Next GUICtrlSetData($Progress, 0) GUICtrlSetData($ProgressLabel, "Status: Finish!") GUICtrlSetData($StartButton, "Start Simulation Progress") EndSwitch WEnd Func _GetRandomName($Lenght=3) Local $RetName = '' For $i = 1 To $Lenght $RetName &= Chr(Random(97, 122, 1)) Next Return $RetName EndFunc The problem is check the size of the file from X to 0 Thanks to all for support Edited January 29, 2012 by johnmcloud
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) No idea how to make it?I see only example with filecopy and progress bar:I don't know how to adapt a function like this to my script, because i don't copy anything, simply delete Edited January 30, 2012 by johnmcloud
Xenobiologist Posted January 30, 2012 Posted January 30, 2012 Where is the problem? The helpfile shows a perfect example. You've got an array holding the pathes of the files you want to delete. This information is all you need for your progressbar. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) The problem is: I have the total size of the file in the array, i don't know how to make the loop for check the decreasing size of the all file. And i have a doubt, is more resource heavy the filegetsize array or is better to check the number of files? Edited January 30, 2012 by johnmcloud
Xenobiologist Posted January 30, 2012 Posted January 30, 2012 I would firstly go for the number. If you got that running, then is shouldn't be a problem to add the lines for the size. Besides, to get the size, you can create a loop before the delete loop, which checks the size for each file and calculates the sum. After that, you can go through the delete loop and decrease the size and number of files by the info you already have in the array of the first loop. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) For the size i have make this: Func Get_Size() Local $iTotalSize = 0 For $i = 1 to $DeleteList[0] $iTotalSize += FileGetSize($DeleteList[$i]) Next Const $1GB = 1024 * 1024 * 1024 Const $1MB = 1024 * 1024 Const $1KB = 1024 $CheckSize = $iTotalSize Select Case $CheckSize > $1GB $Approximate = $CheckSize / $1GB $sComparison = "GB" Case $CheckSize > $1MB And $CheckSize < $1GB $Approximate = $CheckSize / $1MB $sComparison = "MB" Case $CheckSize >= "0" And $CheckSize < $1MB $Approximate = $CheckSize / $1KB $sComparison = "KB" Case Else EndSelect $Approximate = StringLeft($Approximate, 4) ConsoleWrite( "Total: " & $Approximate & " " & $sComparison) EndFunc Thanks Xenobiologist for your time, if you can i need an example on the loop/check decreasing number, i need to see something for understand, sorry Edited January 30, 2012 by johnmcloud
BrewManNH Posted January 30, 2012 Posted January 30, 2012 If you're deleting files, you don't want to monitor the SIZE of the file, just the number of files you're deleting. You won't see any size difference as it's deleted, just total folder size AFTER the file(s) have been deleted, not while the file is being deleted. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) I have check the filesize only of the file before delete in the editbox, with the list of the file, like this: File list to delete ( 11 ) Total: 6.07 MB AutoIt3Au3Check.dat Au3Check.exe Au3Info.exe Au3Info_x64.exe AutoIt v3 Website.url AutoIt.chm AutoIt3.chm AutoIt3.exe AutoIt3Help.exe AutoIt3_x64.exe UDFs3.chm For the progess bar i can check the number on file, is not a problem because i have the array, but i don't know how to loop for check the number of the file Edited January 30, 2012 by johnmcloud
Xenobiologist Posted January 30, 2012 Posted January 30, 2012 Here is a little example. Try is as it is, and then replace the copy command by your delete command :-) #Include <File.au3> _copyProgress("C:DownloadsFotosFrisur", 'C:DownloadsFotosFrisurTest', '*.jpeg') Func _copyProgress($From_dir, $Dest_dir, $filter = '*.*') Local $count = 0, $dir = "" $FileList = _FileListToArray($From_dir, $filter, 0) If(Not IsArray($FileList)) And(@error = 1) Then SetError(-1) ProgressOn("Copy", "Files :", "0 files") For $i = 1 To UBound($FileList) - 1 If FileGetAttrib($FileList[$i]) = "D" Then $dir = "*.*" If FileCopy($From_dir & "" & $FileList[$i] & $dir, $Dest_dir & "", 9) Then $count += 1 ProgressSet($count * 100 / $FileList[0], _ "From: " & $From_dir & "" & @LF & "To: " & $Dest_dir & "" & @LF & $FileList[$i], _ StringFormat('%05.2f', Round(($count * 100 / $FileList[0]), 2)) & " % " & @TAB & $count & "/" & $FileList[0] & " Done") EndIf Sleep(100) ; to see what happens Next ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() Return 1 EndFunc ;==>_copyProgress Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 Seems not work, the progress bar go to 100 but don't delete files, maybe i have do something wrong: #Include <File.au3> $From_dir = "C:test" $filter = "*.*" DelFile() Func DelFile() Local $count = 0, $dir = "" $FileList = _FileListToArray($From_dir, $filter, 0) If(Not IsArray($FileList)) And(@error = 1) Then SetError(-1) ProgressOn("Copy", "Files :", "0 files") For $i = 1 To UBound($FileList) - 1 If FileDelete($FileList[$i]) Then $count += 1 ProgressSet($count * 100 / $FileList[0], _ ;~ "From: " & $From_dir & "" & @LF & "To: " & $Dest_dir & "" & @LF & $FileList[$i], _ StringFormat('%05.2f', Round(($count * 100 / $FileList[0]), 2)) & " % " & @TAB & $count & "/" & $FileList[0] & " Done") EndIf Sleep(100) ; to see what happens Next ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() Return 1 EndFunc ;==>_copyProgress
BrewManNH Posted January 30, 2012 Posted January 30, 2012 Here's how I do it with a function I created that gives you control over a Progressbar and a GUI with a label. It's easy to add this function to a script and just call it with the necessary information, then update it with GUICtrlSetData. expandcollapse popupGlobal $FileCount = 11 Global $ProgressArray = _ProgressGUI("Files to delete = " & $FileCount, 1) GUICtrlSetData($ProgressArray[1], 100) ;Set the progress bar to full For $I = 1 To $FileCount Sleep(500) GUICtrlSetData($ProgressArray[1], 100 - Int(($I / $FileCount) * 100)) ; Reset the position of the progress bar as you delete files, using a percentage of files to delete GUICtrlSetData($ProgressArray[2], "Files to Delete = " & $FileCount - $I) ; updates the label of the GUI with the number of remaining files to delete Next GUIDelete($ProgressArray[0]) ; deletes the ProgressBar GUI ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProgressGui ; Description ...: A small splash screen type GUI with a progress bar and a configurable label ; Syntax.........: _ProgressGUI($s_MsgText = "Text Message", $s_MarqueeType = 0, $i_Fontsize = 14, $s_Font = "Comic Sans MS", $i_XSize = 290, $i_YSize = 100, $b_GUIColor = 0x00080FF, $b_FontColor = 0x0FFFC19) ; Parameters ....: $s_MsgText - Text to display on the GUI ; $s_MarqueeType - [optional] Style of Progress Bar you want to use ; 0 = Marquee style [default] ; 1 = Normal Progress Bar style ; $i_Fontsize - [optional] The font size that you want to display the $s_MsgText at [default = 14] ; $s_Font - [optional] The font you want the message to use [default = "Arial"] ; $i_XSize - [optional] Width of the GUI [Default = 290] - Minimum size is 80 ; $i_YSize - [optional] Height of the GUI [Default = 100] ; $b_GUIColor - [optional] Background color of the GUI [default = 0x00080FF = Blue] ; $s_FontColor - [optional] Color of the text message [default = 0x0FFFC19 = Yellow] ; Return values .: Success - An array containing the ControlID of the GUI created, the control id of the marquee control, and the control ID of the label ; Failure - 0 and @error to 1 if the GUI couldn't be created ; ; Author ........: Bob Marotte (BrewManNH) ; Remarks .......: This will create a customizable GUI with a progress bar. The default style of the progress bar ; using this function is the Marquee style of progress bar. If you call this function with any ; positive, non-zero number it will use the normal progress bar style. All optional parameters ; will accept the Default keyword, an empty string "", or -1 if passed to the function, except ; the color parameters which will not accept the Default keyword. ; Use the return value to delete the GUI when you're done using it (ex. GUIDelete($Returnvalue[0])) ; Related .......: None ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ProgressGUI($s_MsgText = "Text Message", $s_MarqueeType = 0, $i_Fontsize = 14, $s_Font = "Arial", $i_XSize = 290, $i_YSize = 100, $b_GUIColor = 0x00080FF, $b_FontColor = 0x0FFFC19) Local $PBMarquee[3] ; bounds checking/correcting If $i_Fontsize = "" Or $i_Fontsize = Default Or $i_Fontsize = "-1" Then $i_Fontsize = 14 If $i_Fontsize < 1 Then $i_Fontsize = 1 If $i_XSize = "" Or $i_XSize = "-1" Or $i_XSize = Default Then $i_XSize = 290 If $i_XSize < 80 Then $i_XSize = 80 If $i_XSize > @DesktopWidth - 50 Then $i_XSize = @DesktopWidth - 50 If $i_YSize = "" Or $i_YSize = "-1" Or $i_YSize = Default Then $i_YSize = 100 If $i_YSize > @DesktopHeight - 50 Then $i_YSize = @DesktopHeight - 50 If $b_GUIColor = "" Or $b_GUIColor = "-1" Then $b_GUIColor = 0x00080FF If $s_Font = "" Or $s_Font = "-1" Or $s_Font = "Default" Then $s_Font = "Arial" ;create the GUI $PBMarquee[0] = GUICreate("", $i_XSize, $i_YSize, -1, -1, BitOR(0x00400000, 0x80000000)) If @error Then Return SetError(@error, 0, 0) ; if there's any error with creating the GUI, return the error code GUISetBkColor($b_GUIColor, $PBMarquee[0]) ; Create the progressbar If $s_MarqueeType < 1 Then ; if $s_MarqueeType < 1 then use the Marquee style progress bar $PBMarquee[1] = GUICtrlCreateProgress(20, $i_YSize - 20, $i_XSize - 40, 15, 9) ; uses the $PBS_SMOOTH and $PBS_MARQUEE style GUICtrlSendMsg($PBMarquee[1], 1034, True, 20) Else ; If $s_MarqueeType > 0 then use the normal style progress bar $PBMarquee[1] = GUICtrlCreateProgress(20, $i_YSize - 20, $i_XSize - 40, 15, 1) ; Use the $PBS_SMOOTH style EndIf $PBMarquee[2] = GUICtrlCreateLabel($s_MsgText, 20, 20, $i_XSize - 40, $i_YSize - 45) ; create the label for the GUI GUICtrlSetFont(-1, $i_Fontsize, 400, Default, $s_Font) GUICtrlSetColor(-1, $b_FontColor) GUISetState() Return SetError(0, 0, $PBMarquee) ;Return the ControlIDs of the GUI, Progress bar, and the Label (in that order) EndFunc ;==>_ProgressGUI If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) Thanks BrewManNH, but i'd like to integrate the progress bar in the GUI, i'll save you example for the future Edited January 30, 2012 by johnmcloud
BrewManNH Posted January 30, 2012 Posted January 30, 2012 It's just a demo of how to do the progress bar, I used the function because it's a lot easier to use than trying to write something new. The main part of the script is outside of the function though, the technique you'd use is exactly the same. You get the count of the number of files to delete, update the progress bar information using the GUICtrlSetData with the formula I have in my For...Next loop and you'll get your diminishing ProgressBar as your files are deleted. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 (edited) Ok, but i need i little explanation: #Include <File.au3> $From_dir = "C:Test" $filter = "*.*" Local $count = 0, $dir = "" $FileList = _FileListToArray($From_dir, $filter, 0) If(Not IsArray($FileList)) And(@error = 1) Then SetError(-1) Global $ProgressArray = _ProgressGUI("Files to delete = " & $FileList, 1) GUICtrlSetData($ProgressArray[1], 0 ) ;Set the progress bar to zero For $I = 1 To $FileList[0] ;------------------> i need only this to...... Sleep(500) GUICtrlSetData($ProgressArray[1], 0 + Int(($I / $FileList[0]) * 100)) ; Reset the position of the progress bar as you delete files, using a percentage of files to delete GUICtrlSetData($ProgressArray[2], "Files to Delete = " & $FileList[0] - $I) ; updates the label of the GUI with the number of remaining files to delete Next ;------------------> ....this, right? GUIDelete($ProgressArray[0]) ; deletes the ProgressBar GUI 1) Where are i need to add the FileDelete? 2) How to set progreess bar check the number of files instead go away Thanks for support, and sorry for noob question Edited January 30, 2012 by johnmcloud
BrewManNH Posted January 30, 2012 Posted January 30, 2012 You don't add that to this script, you add the information from this script to your script.The first GUICtrlSetData function changes the progress bar using a percentage of files to delete with how many are left to be deleted, and then subtracting that from 100 (100 percent - Int((FilesLeftToDelete/TotalNumberOfFilesBeingDeleted) * 100))). As you delete your files, you update the progress bar to indicate the percentage of files left to be deleted. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
johnmcloud Posted January 30, 2012 Author Posted January 30, 2012 Yes, i'll do, but i want first understand how work it, so i have make a test folder with some files in C:Test
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