Borje Posted August 24, 2007 Share Posted August 24, 2007 (edited) Hello everybody experts please I need little help to have this script to work I am newbee... I would like to have the progressbar to display when files in the folder is deleted. Is there anybody can help me.. I can not have this to works.... Code: ;------------------------------------------------------> Remove Files <--------------------------------------------------- #include <GUIConstants.au3> _CleanFolder1("D:\IM-Backuper") If @error Then MsgBox(0, 'Error', 'Folder D:\Backuper is not found') exit EndIf Func _CleanFolder1($fullpath) Local $dirSize, $file_found, $handle_search, $i = 0, $count = 0 If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf ; Get the amount of file and dirs in the root $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop $count += 1 WEnd FileClose($handle_search) If Not $count Then Return SetError(2, 0, '') EndIf ; Progress through the folder const $PrCopyGui = GUICreate(" Delete all files in folder", 420, 90, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetState(@SW_SHOW) $progressbar1 = GUICtrlCreateProgress (10,20,400,20) $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) $i += 1 Else FileDelete($fullpath & '\' & $file_found) $i += 1 EndIf ProgressSet(100 / $count * $i) WEnd FileClose($handle_search) ;ProgressOff() EndIf EndFunc sleep(2000) exit ;------------------------------------------------------------------------------------------------------------------------- Edited August 24, 2007 by Borje Link to comment Share on other sites More sharing options...
jlorenz1 Posted August 25, 2007 Share Posted August 25, 2007 (edited) Hi, you should work in two steps. In the first step you should collect all files with their full path. After that you have the whole number of files, which you want to delete - so you can set the progressbar in a second step. GUICtrlSetData ($progressbar1, $iActuallyFileIndexNumber*100/$iNumberOfAllFiles) And your code is wrong (because the handle of the control : $progressbar1 is missing) ProgressSet(100 / $count * $i) Send a short notice, if you have still the problem. Johannes Edited August 25, 2007 by jlorenz1 Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
Borje Posted August 25, 2007 Author Share Posted August 25, 2007 Hi, you should work in two steps. In the first step you should collect all files with their full path. After that you have the whole number of files, which you want to delete - so you can set the progressbar in a second step. GUICtrlSetData ($progressbar1, $iActuallyFileIndexNumber*100/$iNumberOfAllFiles) And your code is wrong (because the handle of the control : $progressbar1 is missing) ProgressSet(100 / $count * $i) Send a short notice, if you have still the problem. Johannes Hello Johannes thanks for your help but can you implement this in my code as I is a newbee in this please can you compled my code?? Borje Link to comment Share on other sites More sharing options...
jlorenz1 Posted August 25, 2007 Share Posted August 25, 2007 (edited) Hi Borje, perhaps it is an error of converting source code in html, but the first thing, that you should ever do, is to work with tab stops like this expandcollapse popup#include <GUIConstants.au3> _CleanFolder1("D:\IM-Backuper") If @error Then MsgBox(0, 'Error', 'Folder D:\Backuper is not found') exit EndIf Func _CleanFolder1($fullpath) Local $dirSize, $file_found, $handle_search, $i = 0, $count = 0 If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf ; Get the amount of file and dirs in the root $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop $count += 1 WEnd FileClose($handle_search) If Not $count Then Return SetError(2, 0, '') EndIf ; Progress through the folder const $PrCopyGui = GUICreate(" Delete all files in folder", 420, 90, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetState(@SW_SHOW) $progressbar1 = GUICtrlCreateProgress (10,20,400,20) $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) $i += 1 Else FileDelete($fullpath & '\' & $file_found) $i += 1 EndIf ProgressSet(100 / $count * $i) WEnd FileClose($handle_search) ;ProgressOff() EndIf EndFunc sleep(2000) exit So you have a better overview about loops and condition statements. Johannes from Germany Edited August 25, 2007 by jlorenz1 Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
Borje Posted August 25, 2007 Author Share Posted August 25, 2007 Hi Johannes I have test but I not see any progressbar ?? Link to comment Share on other sites More sharing options...
jlorenz1 Posted August 25, 2007 Share Posted August 25, 2007 (edited) Hello Johannes thanks for your help but can you implement this in my code as I is a newbee in this please can you compled my code?? Borje Hi Borje, this works. It isn't very elegant, cause deleting subfolders are counting like the deleting of one file, but it has a better structure as before. Johannes expandcollapse popup; first #include #include <GUIConstants.au3> #include <array.au3>; only necessary to show you the content of the array ;second opt Opt("TrayIconDebug", 0);this is generally useful, if you are unsure in scripting ;third Declaration of variables Global $avTableOfFilesAndSubfolders[1][2];this is an array something like a table actually with 1 row and 2 columns $avTableOfFilesAndSubfolders[0][0]=Cell A1 $avTableOfFilesAndSubfolders[0][1]=Cell B1 ;fourth GUI const $PrCopyGui = GUICreate(" Delete all files in folder", 420, 90, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $progressbar1 = GUICtrlCreateProgress (10,20,400,20) GUISetState(@SW_SHOW) ; this the second part of the GUI section While 1 _CleanFolder1("D:\IM-Backuper") If @error == 1 then MsgBox(4160,'Info', 'File doesnt exist') ;$msg = GUIGetMsg() Wend ;fifth function always at the end! Func _CleanFolder1($fullpath) Local $dirSize, $file_found, $handle_search, $i = 0, $count = 0 If FileExists ($fullpath) then ; Get the amount of file and dirs in the root $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop $count += 1 ReDim $avTableOfFilesAndSubfolders[$count+ 1][2];attach one row more the array/table $avTableOfFilesAndSubfolders[$count][0]= $fullpath & '\' & $file_found;attention arrays starts always with cero!!! Second row is $avTableOfFilesAndSubfolders[1][0] not $avTableOfFilesAndSubfolders[2][0] If StringInStr(FileGetAttrib($fullpath & '\' & $file_found ), 'D') then $avTableOfFilesAndSubfolders[$count][1]= 1; this is a folder, which will be deleted with DirRemove() Else $avTableOfFilesAndSubfolders[$count][1]= 0; this is a file, which will be deleted with FileDelete() EndIf WEnd FileClose($handle_search) $avTableOfFilesAndSubfolders[0][0]= UBound($avTableOfFilesAndSubfolders)-1; max. number of files and subfolders If Not $count Then Return SetError(2, 0, '') EndIf _ArrayDisplay($avTableOfFilesAndSubfolders, 'Content of $avTableOfFilesAndSubfolders for a better understanding'); comment it out, if you are sure in using arrays ; Progress through the folder If $avTableOfFilesAndSubfolders[0][0] > 0 then For $i = 1 to $avTableOfFilesAndSubfolders[0][0] If $avTableOfFilesAndSubfolders[$i][1]== 1 then DirRemove($avTableOfFilesAndSubfolders[$i][0], 1); last parameter for recursive deleting If $avTableOfFilesAndSubfolders[$i][1]== 0 then FileDelete($avTableOfFilesAndSubfolders[$i][0]) GUICtrlSetData ($progressbar1, $i*100/Number($avTableOfFilesAndSubfolders[0][0])) Next MsgBox(4096, 'Info', $avTableOfFilesAndSubfolders[0][0] & ' files and subfolders successfully deleted') Else SetError (2, 0, 2) ;MsgBox(4096,'Info','Canceled. This folder contains no files and/or subfolders') EndIf Else SetError (1, 0, 1) ;MsgBox(4096,"Info", "Canceled. This folder: " & $fullpath & " doesn't exist.") EndIf Exit EndFuncborje.au3 Edited August 25, 2007 by jlorenz1 Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] Link to comment Share on other sites More sharing options...
Borje Posted August 25, 2007 Author Share Posted August 25, 2007 Johannes you is a super programmer, ok I want to delete the subfolders only What I do I would only delete the subfolders in the mainfolder... I not need the choice every time I run this I want to delete all subfolders i think you know. My code working but not with progressbar... Link to comment Share on other sites More sharing options...
jlorenz1 Posted August 25, 2007 Share Posted August 25, 2007 Johannes you is a super programmer, ok I want to delete the subfolders only What I do I would only delete the subfolders in the mainfolder... I not need the choice every time I run this I want to delete all subfolders i think you know. My code working but not with progressbar...Hi, I've updated the last source code example. Johannes Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post] 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