mud409 Posted July 11, 2013 Share Posted July 11, 2013 (edited) I'm trying to add a section onto my script that allows you to delete xml files before it combines all of them. This script does all of that, if I manually enter the array number in the case. How do I generate a Select loop that corresponds with the array of buttons I've generated? expandcollapse popup#include <array.au3> #include <guiconstantsex.au3> #include "GUIScrollbars_Ex.au3" ;$folder = FileSelectFolder("Find the folder including your text files to combine", "", 2 ) ;If @error = 1 Then Exit $folder = "C:\IWDB\Genres" FileChangeDir($folder) ;Recursive search for txt (or TXT) files only $Array = RecursiveFileSearch($folder, "(?i)\.(xml)\z") $Array2 = $Array $hGUI = GUICreate("Genres", 220, 500) $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Genres", 10, 10, 200, 12) ;If any files were found If $Array[0] > 0 Then ;_ArrayDisplay($Array) ;Output destination ;$save = FileSaveDialog("Select where to save your file" , "" , "Text files (*.txt)" , 16 ) $save = @ScriptDir & "\genres.xml" If @error = 1 Then Exit ;Loop through found files $scroll_height = 12 For $X = 2 to $Array[0] ; $file = FileRead($Array[$X]) ; FileWrite($output, $file) $String = StringSplit($Array[$X], "\") $String2 = StringReplace($String[$String[0]], "_", " ") $String3 = StringReplace($String2, ".xml", "") $Array2[$X] = GUICtrlCreateCheckBox($String3, -1, 1, 200, 15) $scroll_height = $scroll_height + 16 Next _GUIScrollbars_Generate($hGUI, 0, $scroll_height) GUISetState(@SW_SHOW, "Delete Genres") While 1 $gMsg = GUIGetMsg() Switch $gMsg Case $Array2[2] $MSGresult = MsgBox(4, "Genre Delete", "Delete Genre?") Select Case $MSGresult = 6 ;Yes GUICtrlSetState($Array2[2] , $GUI_DISABLE) FileDelete($Array[2]) Case $MSGresult = 7 ;No GUICtrlSetState($Array2[2] , $GUI_UNCHECKED) EndSelect Case $Array2[3] $MSGresult = MsgBox(4, "Genre Delete", "Delete Genre?") Select Case $MSGresult = 6 ;Yes GUICtrlSetState($Array2[3] , $GUI_DISABLE) FileDelete($Array[2]) Case $MSGresult = 7 ;No GUICtrlSetState($Array2[3] , $GUI_UNCHECKED) EndSelect EndSwitch Wend ;start combining disabled $Array = RecursiveFileSearch($folder, "(?i)\.(xml)\z") $output = FileOpen($save, 1) For $X = 1 to $Array[0] ; $file = FileRead($Array[$X]) ; FileWrite($output, $file) Next FileClose($output) EndIf ;RFSstartdir: Path to starting folder ;RFSpattern: RegEx pattern to match i.e. "(?i)\.(mp3)" find all mp3 files - case insensitive, "(?-i)\.(mp3|txt)" find all mp3 and txt files - case sensitive ;RFSrecurse: TRUE = Recursive, FALSE = Non-recursive ;RFSdepth: Internal use only Func RecursiveFileSearch($RFSstartDir, $RFSpattern = ".", $RFSrecurse = true, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) Global $RFSarray[$RFSfilecount[1] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSpattern, $RFSrecurse, $RFSdepth + 1) Else If StringRegExp($RFSnext, $RFSpattern, 0) Then ;Append filename to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext ;Increment filecount $RFSarray[0] += 1 EndIf EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then Redim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearch Edited July 11, 2013 by mud409 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 11, 2013 Moderators Share Posted July 11, 2013 Mud409,I have amended your code so i can use it on my system (and used my recursive file search UDF which I think is better ) but I hope you can see how I determine which checkbox has been checked: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include "GUIScrollbars_Ex.au3" #include <RecFileListToArray.au3> $sFolder = @ScriptDir FileChangeDir($sFolder) ;Recursive search for files $aList = _RecFileListToArray($sFolder, "*.bak", 1, 1, 0, 0) $aList2 = $aList $hGUI = GUICreate("Genres", 220, 500) $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Genres", 10, 10, 200, 12) ;If any files were found If $aList[0] > 0 Then ;Output destination $sSave = @ScriptDir & "\genres.xml" ;Loop through found files $iScroll_Height = 12 For $i = 1 To $aList[0] $String = StringSplit($aList[$i], "\") $String2 = StringReplace($String[$String[0]], "_", " ") $String3 = StringReplace($String2, ".au3", "") $aList2[$i] = GUICtrlCreateCheckbox($String3, -1, 1, 200, 15) $iScroll_Height = $iScroll_Height + 16 Next ; Set the bounds for the Checkbox ControlIDs - this will only work if they are the only controls created in that loop <<<<<<<<<<<<<< $iStart = $aList2[1] $iEnd = $aList2[$aList2[0]] _GUIScrollbars_Generate($hGUI, 0, $iScroll_Height) GUISetState(@SW_SHOW, "Delete Genres") While 1 $iMsg = GUIGetMsg() Switch $iMsg ; You need a Case to close the GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $iStart To $iEnd For $i = 1 To $aList2[0] If $aList2[$i] = $iMsg Then Switch MsgBox(4, "Genre Delete", "Delete Genre?") Case 6 ;Yes GUICtrlSetState($aList2[$i], $GUI_DISABLE) FileDelete($aList[$i]) ; Delete file _ArrayDelete($aList, $i) ; Delete from array $aList[0] -= 1 _ArrayDisplay($aList, "After deletion") Case 7 ;No GUICtrlSetState($aList2[$i], $GUI_UNCHECKED) EndSwitch ExitLoop EndIf Next EndSwitch WEnd ; How do you expect to get here? You need something to escape from the infinite loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;start combining disabled ;$aList = RecursiveFileSearch($sFolder, "(?i)\.(xml)\z") ; I do not thonk this is needed - we have deleted the elements earlier <<<<<<<<<<< $output = FileOpen($sSave, 1) For $i = 1 To $aList[0] ; $file = FileRead($aList[$i]) ; FileWrite($output, $file) Next FileClose($output) EndIfPlease ask if you have any questions. 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...
mud409 Posted July 11, 2013 Author Share Posted July 11, 2013 Excellent. Exactly what I needed. I thought I added those missing chunks back but guess I forgot...and thanks for the upgrade in UDF. 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