logonui Posted June 27, 2008 Share Posted June 27, 2008 (edited) Hi all, I am having a few problems with a script I am writing, I have managed to create a series of arrays which retrieve the file and folder list for up to 7directory levels and create a tree view showing this. The issues i am having are: 1. The script is kind of messy but I can't think of any way to clean it up 2. It runs stupidly slowly when trying to refresh the tree to include updates that the user has made 3. The program stops running if the folder list reaches 3873 items, is this a limit of AutoIT or am I doing something wrong expandcollapse popup#include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> Dim $Tree1[20000] Dim $Tree1A[20000] Dim $Tree2[20000] Dim $Tree2B[20000] Dim $Tree3[20000] Dim $Tree3C[20000] Dim $Tree4[20000] Dim $Tree4D[20000] Dim $Tree5[20000] Dim $Tree5E[20000] Dim $Tree6[20000] Dim $Tree6F[20000] Dim $Tree7[20000] Dim $Tree7G[20000] Global $Tree1[20000] Global $Tree1A[20000] Global $Tree2[20000] Global $Tree2B[20000] Global $Tree3[20000] Global $Tree3C[20000] Global $Tree4[20000] Global $Tree4D[20000] Global $Tree5[20000] Global $Tree5E[20000] Global $Tree6[20000] Global $Tree6F[20000] Global $Tree7[20000] Global $Tree7G[20000] Global $TreeView $1 = GUICreate("GUI",800,600,-1,-1,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX)) GUISetBkColor(0xFFFFFF,$1) GUISetFont(10,400,-1,"Arial",$1) $TreeView = GUICtrlCreateTreeView(0,0,800,500) _Populate() GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect Wend Func _Populate() $RootFolder = FileSelectFolder ( "Select Folder", "") $FOArray1 = _FileListToArray ($RootFolder, "*",2);Level 1 If IsArray($FOArray1) Then $a = 1 For $1 = 1 To $FOArray1[0] $a = $a + 1 $Tree1[$a] = GUICtrlCreateTreeViewitem($FOArray1[$1], $TreeView) GUICtrlSetColor($Tree1[$a],0x2A2AFF) $FOArray2 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1], "*",2);Level 2 If IsArray($FOArray2) Then $b = 1 For $2 = 1 To $FOArray2[0] $b = $b + 1 $Tree2[$b] = GUICtrlCreateTreeViewitem($FOArray2[$2], $Tree1[$a]) GUICtrlSetColor($Tree2[$b],0x2A2AFF) $FOArray3 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2], "*",2);Level3 If IsArray($FOArray3) Then $c = 1 For $3 = 1 To $FOArray3[0] $c = $c + 1 $Tree3[$c] = GUICtrlCreateTreeViewitem($FOArray3[$3], $Tree2[$b]) GUICtrlSetColor($Tree3[$c],0x2A2AFF) $FOArray4 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3], "*",2);Level 4 If IsArray($FOArray4) Then $d = 1 For $4 = 1 To $FOArray4[0] $d = $d + 1 $Tree4[$d] = GUICtrlCreateTreeViewitem($FOArray4[$4], $Tree3[$c]) GUICtrlSetColor($Tree4[$d],0x2A2AFF) $FOArray5 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4], "*",2);Level 5 If IsArray($FOArray5) Then $e = 1 For $5 = 1 To $FOArray5[0] $e = $e + 1 $Tree5[$e] = GUICtrlCreateTreeViewitem($FOArray5[$5], $Tree4[$d]) GUICtrlSetColor($Tree5[$e],0x2A2AFF) $FOArray6 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4]&"\"&$FOArray5[$5], "*",2);Level 6 If IsArray($FOArray6) Then $f = 1 For $6 = 1 To $FOArray6[0] $f = $f + 1 $Tree6[$f] = GUICtrlCreateTreeViewItem($FOArray6[$6], $Tree5[$e]) GUICtrlSetColor($Tree6[$f],0x2A2AFF) $FOArray7 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4]&"\"&$FOArray5[$5]&"\"&$FOArray6[$6], "*",2);Level 7 If IsArray($FOArray7) Then $g = 1 For $7 = 1 To $FOArray7[0] $g = $g + 1 $Tree7[$g] = GUICtrlCreateTreeViewItem($FOArray7[$7], $Tree6[$f]) GUICtrlSetColor($Tree7[$g],0x2A2AFF) Next EndIf $FIArray7 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4]&"\"&$FOArray5[$5]&"\"&$FOArray6[$6], "*",1) If IsArray($FIArray7) Then $g7 = 1 For $7g = 1 To $FIArray7[0] $g7 = $g7 + 1 $Tree7G[$g7] = GUICtrlCreateTreeViewItem($FIArray7[$7g], $Tree6[$f]) Next EndIf Next EndIf $FIArray6 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4]&"\"&$FOArray5[$5], "*",1) If IsArray($FIArray6) Then $f6 = 1 For $6f = 1 To $FIArray6[0] $f6 = $f6 + 1 $Tree6F[$f6] = GUICtrlCreateTreeViewItem($FIArray6[$6f], $Tree5[$e]) Next EndIf Next EndIf $FIArray5 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3]&"\"&$FOArray4[$4], "*",1) If IsArray($FIArray5) Then $e5 = 1 For $5e = 1 To $FIArray5[0] $e5 = $e5 + 1 $Tree5E[$e5] = GUICtrlCreateTreeViewItem($FIArray5[$5e], $Tree4[$d]) Next EndIf Next EndIf $FIArray4 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2]&"\"&$FOArray3[$3], "*",1) If IsArray($FIArray4) Then $d4 = 1 For $4d = 1 To $FIArray4[0] $d4 = $d4 + 1 $Tree4D[$d4] = GUICtrlCreateTreeViewItem($FIArray4[$4d], $Tree3[$c]) Next EndIf Next EndIf $FIArray3 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1]&"\"&$FOArray2[$2], "*",1) If IsArray($FIArray3) Then $c3 = 1 For $3c = 1 To $FIArray3[0] $c3 = $c3 + 1 $Tree3c[$c3] = GUICtrlCreateTreeViewItem($FIArray3[$3c], $Tree2[$b]) Next EndIf Next EndIf $FIArray2 = _FileListToArray ($RootFolder&"\"&$FOArray1[$1], "*",1) If IsArray($FIArray2) Then $b2 = 1 For $2b = 1 To $FIArray2[0] $b2 = $b2 + 1 $Tree2b[$b2] = GUICtrlCreateTreeViewItem($FIArray2[$2b], $Tree1[$a]) Next EndIf Next EndIf $FIArray1 = _FileListToArray ($RootFolder, "*",1) If IsArray($FIArray1) Then $a1 = 1 For $1a = 1 To $FIArray1[0] $a1 = $a1 + 1 $Tree1a[$a1] = GUICtrlCreateTreeViewItem($FIArray1[$1a], $TreeView) Next EndIf EndFunc Cheers Lee Edited June 27, 2008 by logonui Link to comment Share on other sites More sharing options...
Triblade Posted June 27, 2008 Share Posted June 27, 2008 The only thing I can give you is that you can stack Dim's and Global's Dim $1, $2, $3 ; etc Global $1, $2, $3 ; etc My active project(s): A-maze-ing generator (generates a maze) My archived project(s):Â Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
logonui Posted June 27, 2008 Author Share Posted June 27, 2008 The only thing I can give you is that you can stack Dim's and Global'sDim $1, $2, $3 ; etcGlobal $1, $2, $3 ; etcCheersI tried doing that initially like i do will all of my other scripts but it just kept erroring out, strange but not a major issue.Cheers anywayLee Link to comment Share on other sites More sharing options...
ChrisL Posted June 27, 2008 Share Posted June 27, 2008 Try this... It's not limited to 7 directory depth expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Dim $treeView[1] $1 = GUICreate("GUI",800,600,-1,-1,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX)) GUISetBkColor(0xFFFFFF,$1) GUISetFont(10,400,-1,"Arial",$1) $treeView[0] = GUICtrlCreateTreeView(0,0,800,500) $Folder = FileSelectFolder ( "Select Folder", "") _Populate($folder,$treeView[0]) GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect Wend Func _Populate($current,$tree) If StringRight($current,1) = "\" then $current = StringTrimRight($current,1) Local $search = FileFindFirstFile($current & "\*.*") While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") Then Redim $treeView[Ubound($TreeView) +1] $treeView[Ubound($TreeView) - 1] = GUICtrlCreateTreeViewItem($file,$tree) EndIf If StringInStr(FileGetAttrib($current & "\" & $file), "D") Then Redim $treeView[Ubound($TreeView) +1] $treeView[Ubound($TreeView) - 1] = GUICtrlCreateTreeViewItem($file,$tree) GUICtrlSetColor(-1,0x2A2AFF) _Populate($current & "\" & $file, $treeView[Ubound($TreeView) -1]) EndIf WEnd FileClose($search) EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
rudi Posted June 27, 2008 Share Posted June 27, 2008 Hi. A very convenient and fast recurse FileListToArray is (?was?) provided in a UDF package, _FileListToArrayFaster1e.zip I used it with Autoit Version 3.2.10.0, iirc I had troubles with 3.2.12.0, but I'm not sure about that. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! 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