Nhardel Posted December 30, 2008 Posted December 30, 2008 Okay, so I'm pretty sure I thought about this way to hard! I am trying to build a treeviewlist of folder hierarchy contained within a zipfile. I am using the 7zip udf from rasim (UDF here) I use the call DllStructGetData($tINDIVIDUALINFO, "szFileName") to get the full path of a file contained within the zip. I build a 1d array based on that info.Example:[0]|11[1]|Lab Backup\7-zip32.dll[2]|Lab Backup\App Lab Backup.exe[3]|Lab Backup\Backup.au3[4]|Lab Backup\logs\20081229.log[5]|Lab Backup\settings.ini[6]|Lab Backup\test1\7-zip32.dll[7]|Lab Backup\test1\Backup.au3[8]|Lab Backup\test1\settings.ini[9]|Lab Backup\test1\test2\7-zip32.dll[10]|Lab Backup\test1\test2\Backup.au3[11]|Lab Backup\test1\test2\settings.iniI tried to figure out a way to get that info into a treeviewlist that would break it down into folder hierarchy. No go for me atleastI then decided that I would break out each instance into a 2d array with string split I also added a "\" at the end of each folder and gave each instance a depth# on column 0 of each row starting with 1 this produced an array of:[0]|||||[1]|2|Lab Backup\|7-zip32.dll||[2]|2|Lab Backup\|App Lab Backup.exe||[3]|2|Lab Backup\|Backup.au3||[4]|3|Lab Backup\|logs\|20081229.log|[5]|2|Lab Backup\|settings.ini||[6]|3|Lab Backup\|test1\|7-zip32.dll|[7]|3|Lab Backup\|test1\|Backup.au3|[8]|3|Lab Backup\|test1\|settings.ini|[9]|4|Lab Backup\|test1\|test2\|7-zip32.dll[10]|4|Lab Backup\|test1\|test2\|Backup.au3[11]|4|Lab Backup\|test1\|test2\|settings.iniThe best that I could get with that was each row correctly breaking itself down but no overlapping of folders between the rows in the arraySee I told you I was probably going way overboard.So then I thought the problem came from that fact that as I read my array that I would see multiple instances of the same folder structure so I revamped again so that it made more sence, at least to me it did. Outcome is this:[0]|11|1|6|5|3[1]|2|Lab Backup\|7-zip32.dll||[2]|2||App Lab Backup.exe||[3]|2||Backup.au3||[4]|3||logs\|20081229.log|[5]|2||settings.ini||[6]|3||test1\|7-zip32.dll|[7]|3|||Backup.au3|[8]|3|||settings.ini|[9]|4|||test2\|7-zip32.dll[10]|4||||Backup.au3[11]|4||||settings.iniI have posted the code here CODE#include <Date.au3>#include <7Zip.au3>#include <array.au3>#include <GUIConstants.au3>#include <GuiTreeView.au3>Opt("GUIOnEventMode", 1)$drivemap = DriveMapAdd("*","\\usandl0000\app lab backup")Global $1d = 1, $2d =1Dim $testArray[1],$treeviewarray[$1d][$2d]$ArcFile = FileOpenDialog("Select archive", "", "Archive Files (*.7z;*.zip;*.gzip;*.bzip2;*.tar)")If @error Then Exit$hArc = _7ZipOpenArchive(0, $ArcFile)If $hArc = 0 Then Exit MsgBox(16, "_7ZipOpenArchive", "Error occured")$tINDIVIDUALINFO = _7ZipFindFirst($hArc, "*.*")If $tINDIVIDUALINFO = -1 Then Exitlogfile($tINDIVIDUALINFO)While 1 $tINDIVIDUALINFO = _7ZipFindNext($hArc, $tINDIVIDUALINFO) If $tINDIVIDUALINFO = 0 Then ExitLoop logfile($tINDIVIDUALINFO)WEndfunc logfile($tINDIVIDUALINFO) _ArrayAdd($testArray, DllStructGetData($tINDIVIDUALINFO, "szFileName"))EndFunc_7ZipCloseArchive($hArc)$a = DriveMapDel($drivemap)$testArray[0] = ubound($testArray)-1_ArrayDisplay($testArray)$1d = $testArray[0] +1redim $treeviewarray[$1d][$2d]_ArraySort($testArray,0,1); Build special array for treeviewfor $a = 1 to $testArray[0] $b = StringSplit($testArray[$a],"\") for $c = 1 to $b[0]-1 $b[$c] = $b[$c]&"\" next ConsoleWrite($a & " Check depth: $b[0] ="&$b[0]& " and $2d="& $2d & @crlf) if $b[0] >= $2d Then redim $treeviewarray[$1d][$b[0]+1] $2d = $b[0] +1 endif for $c = 0 to $b[0] $treeviewarray[$a][$c] = $b[$c] nextnext_ArrayDisplay($treeviewarray)$treeviewarray[0][0] = ubound($treeviewarray,1)-1 $treeviewarray[0][1] = UBound($treeviewarray,2)-1;~ _ArrayDisplay($treeviewarray)For $a = 1 to $treeviewarray[0][1] $b = 0 for $c = 1 to $treeviewarray[0][0] if $treeviewarray[$c][$a] <> "" then $b = $b + 1 $d = _arrayfindall($treeviewarray,$treeviewarray[$c][$a],1,"","","",$a) for $e = 1 to Ubound($d)-1 $treeviewarray[$d[$e]][$a] ="" Next EndIf Next $treeviewarray[0][$a] = $bNext_ArrayDisplay($treeviewarray)Don't lynch me too hard I am very aware that the code is very dirty and terrible if at all documented This was more a POC part of my project that I just keeped building on. So my problem is where to go from here. I am pretty sure I need to use recursive disccover of my array to build the treeview but not real sure how to go about it. Any ideas. I did search the forums and didnt really find anything about building treeviews from an array. If I missed something I appoligize, just point me in the direction.
enaiman Posted December 31, 2008 Posted December 31, 2008 (edited) Took me a while but it's working ... you'll have to figure out how to "sort" the tree so it will list items in order ... blah-blah.. You will need an array with your file list. expandcollapse popup#include <GUIConstantsEx.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> Global $done = 0 Global $lvl_counter = 10 Global $TreeView[10000] Global $tree_level = 1 Global $parent_nodes Global $nodes Dim $a[12] $a[1]="Lab Backup\7-zip32.dll" $a[2]="Lab Backup\App Lab Backup.exe" $a[3]="Lab Backup\Backup.au3" $a[4]="Lab Backup\logs\20081229.log" $a[5]="Lab Backup\settings.ini" $a[6]="Lab Backup\test1\7-zip32.dll" $a[7]="Lab Backup\test1\Backup.au3" $a[8]="Lab Backup\test1\settings.ini" $a[9]="Lab Backup\test1\test2\7-zip32.dll" $a[10]="Lab Backup\test1\test2\Backup.au3" $a[11]="Lab Backup\test1\test2\settings.ini" Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 267, 308, 193, 125) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $TreeView1 = GUICtrlCreateTreeView(8, 8, 249, 289) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _BuildTree() While 1 Sleep(100) WEnd Func Form1Close() Exit EndFunc Func _BuildTree() Do $match = 0 For $i=1 To UBound($a) -1 $branch = StringSplit($a[$i], "\") If $branch[0] >= $tree_level Then If Not StringInStr($nodes, $branch[$tree_level]) Then;if node not created If $tree_level = 1 Then ;if root (level 1) If Not StringInStr($parent_nodes, $branch[$tree_level]) Then;if not added yet $TreeView[$lvl_counter] = GUICtrlCreateTreeViewItem($branch[$tree_level], $TreeView1);add node $parent_nodes &= $branch[$tree_level]&"|"&$lvl_counter&"%";record node name and array index for future use $lvl_counter +=1 ;increment the index EndIf Else If StringInStr($parent_nodes, $branch[$tree_level -1]) Then;if parent found in $parent_nodes $pos = StringInStr($parent_nodes, $branch[$tree_level -1]) $idx = StringMid($parent_nodes, $pos+1+ StringLen($branch[$tree_level -1]) , 2) $TreeView[$lvl_counter] = GUICtrlCreateTreeViewItem($branch[$tree_level], $TreeView[$idx]) $nodes &= $branch[$tree_level]&"|"&$lvl_counter&"%" $lvl_counter +=1 EndIf EndIf EndIf $match += 1 Else ContinueLoop EndIf Next If $tree_level > 1 Then $parent_nodes = $nodes $nodes = "" $tree_level += 1 If $match = 0 Then $done = 1;if no more levels then prepare to exit loop Until $done = 1 GUICtrlSetState($TreeView[10], $GUI_EXPAND);expand root ReDim $TreeView[$lvl_counter +1] ;reDim the array EndFunc Good luck, Edited December 31, 2008 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
PsaltyDS Posted December 31, 2008 Posted December 31, 2008 Okay, so I'm pretty sure I thought about this way to hard! I am trying to build a treeviewlist of folder hierarchy contained within a zipfile. I am using the 7zip udf from rasim (UDF here) I use the call DllStructGetData($tINDIVIDUALINFO, "szFileName") to get the full path of a file contained within the zip. I build a 1d array based on that info. Example: [0]|11 [1]|Lab Backup\7-zip32.dll [2]|Lab Backup\App Lab Backup.exe [3]|Lab Backup\Backup.au3 [4]|Lab Backup\logs\20081229.log [5]|Lab Backup\settings.ini [6]|Lab Backup\test1\7-zip32.dll [7]|Lab Backup\test1\Backup.au3 [8]|Lab Backup\test1\settings.ini [9]|Lab Backup\test1\test2\7-zip32.dll [10]|Lab Backup\test1\test2\Backup.au3 [11]|Lab Backup\test1\test2\settings.ini I tried to figure out a way to get that info into a treeviewlist that would break it down into folder hierarchy. No go for me atleast I then decided that I would break out each instance into a 2d array with string split I also added a "\" at the end of each folder and gave each instance a depth# on column 0 of each row starting with 1 this produced an array of: [0]||||| [1]|2|Lab Backup\|7-zip32.dll|| [2]|2|Lab Backup\|App Lab Backup.exe|| [3]|2|Lab Backup\|Backup.au3|| [4]|3|Lab Backup\|logs\|20081229.log| [5]|2|Lab Backup\|settings.ini|| [6]|3|Lab Backup\|test1\|7-zip32.dll| [7]|3|Lab Backup\|test1\|Backup.au3| [8]|3|Lab Backup\|test1\|settings.ini| [9]|4|Lab Backup\|test1\|test2\|7-zip32.dll [10]|4|Lab Backup\|test1\|test2\|Backup.au3 [11]|4|Lab Backup\|test1\|test2\|settings.ini The best that I could get with that was each row correctly breaking itself down but no overlapping of folders between the rows in the array See I told you I was probably going way overboard. So then I thought the problem came from that fact that as I read my array that I would see multiple instances of the same folder structure so I revamped again so that it made more sence, at least to me it did. Outcome is this: [0]|11|1|6|5|3 [1]|2|Lab Backup\|7-zip32.dll|| [2]|2||App Lab Backup.exe|| [3]|2||Backup.au3|| [4]|3||logs\|20081229.log| [5]|2||settings.ini|| [6]|3||test1\|7-zip32.dll| [7]|3|||Backup.au3| [8]|3|||settings.ini| [9]|4|||test2\|7-zip32.dll [10]|4||||Backup.au3 [11]|4||||settings.ini I have posted the code here CODE#include <Date.au3> #include <7Zip.au3> #include <array.au3> #include <GUIConstants.au3> #include <GuiTreeView.au3> Opt("GUIOnEventMode", 1) $drivemap = DriveMapAdd("*","\\usandl0000\app lab backup") Global $1d = 1, $2d =1 Dim $testArray[1],$treeviewarray[$1d][$2d] $ArcFile = FileOpenDialog("Select archive", "", "Archive Files (*.7z;*.zip;*.gzip;*.bzip2;*.tar)") If @error Then Exit $hArc = _7ZipOpenArchive(0, $ArcFile) If $hArc = 0 Then Exit MsgBox(16, "_7ZipOpenArchive", "Error occured") $tINDIVIDUALINFO = _7ZipFindFirst($hArc, "*.*") If $tINDIVIDUALINFO = -1 Then Exit logfile($tINDIVIDUALINFO) While 1 $tINDIVIDUALINFO = _7ZipFindNext($hArc, $tINDIVIDUALINFO) If $tINDIVIDUALINFO = 0 Then ExitLoop logfile($tINDIVIDUALINFO) WEnd func logfile($tINDIVIDUALINFO) _ArrayAdd($testArray, DllStructGetData($tINDIVIDUALINFO, "szFileName")) EndFunc _7ZipCloseArchive($hArc) $a = DriveMapDel($drivemap) $testArray[0] = ubound($testArray)-1 _ArrayDisplay($testArray) $1d = $testArray[0] +1 redim $treeviewarray[$1d][$2d] _ArraySort($testArray,0,1) ; Build special array for treeview for $a = 1 to $testArray[0] $b = StringSplit($testArray[$a],"\") for $c = 1 to $b[0]-1 $b[$c] = $b[$c]&"\" next ConsoleWrite($a & " Check depth: $b[0] ="&$b[0]& " and $2d="& $2d & @crlf) if $b[0] >= $2d Then redim $treeviewarray[$1d][$b[0]+1] $2d = $b[0] +1 endif for $c = 0 to $b[0] $treeviewarray[$a][$c] = $b[$c] next next _ArrayDisplay($treeviewarray) $treeviewarray[0][0] = ubound($treeviewarray,1)-1 $treeviewarray[0][1] = UBound($treeviewarray,2)-1 ;~ _ArrayDisplay($treeviewarray) For $a = 1 to $treeviewarray[0][1] $b = 0 for $c = 1 to $treeviewarray[0][0] if $treeviewarray[$c][$a] <> "" then $b = $b + 1 $d = _arrayfindall($treeviewarray,$treeviewarray[$c][$a],1,"","","",$a) for $e = 1 to Ubound($d)-1 $treeviewarray[$d[$e]][$a] ="" Next EndIf Next $treeviewarray[0][$a] = $b Next _ArrayDisplay($treeviewarray)Don't lynch me too hard I am very aware that the code is very dirty and terrible if at all documented This was more a POC part of my project that I just keeped building on. So my problem is where to go from here. I am pretty sure I need to use recursive disccover of my array to build the treeview but not real sure how to go about it. Any ideas. I did search the forums and didnt really find anything about building treeviews from an array. If I missed something I appoligize, just point me in the direction. Since that part works, all of the 7-zip stuff is a useless distraction from the issue of how to populate the TreeView. This demo takes your data from an array and populates a TreeView with it: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <array.au3>; Only for _ArrayDisplay() Opt("GUIOnEventMode", 1) Global $testArray[11] = ["Lab Backup\7-zip32.dll", "Lab Backup\App Lab Backup.exe", _ "Lab Backup\Backup.au3", "Lab Backup\logs\20081229.log", "Lab Backup\settings.ini", _ "Lab Backup\test1\7-zip32.dll", "Lab Backup\test1\Backup.au3", _ "Lab Backup\test1\settings.ini", "Lab Backup\test1\test2\7-zip32.dll", _ "Lab Backup\test1\test2\Backup.au3", "Lab Backup\test1\test2\settings.ini"] _ArrayDisplay($testArray, "$testArray") Global $hGUI, $hTV1, $sPathList = Chr(1) $hGUI = GUICreate("Test", 400, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") $hTV1 = _GUICtrlTreeView_Create($hGUI, 20, 10, 360, 230) $idButton = GUICtrlCreateButton("Populate TreeView", 150, 260, 100, 30) GUICtrlSetOnEvent($idButton, "_PopulateTV1") GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(10) WEnd Func _PopulateTV1() _GUICtrlTreeView_BeginUpdate($hTV1) For $n = 0 To UBound($testArray) - 1 _AddToTV1($testArray[$n]) Next _GUICtrlTreeView_EndUpdate($hTV1) EndFunc Func _AddToTV1($sPath) Local $avPath = StringSplit($sPath, "\") Local $hParent = 0; 0 = Root Local $hFound, $sTestPath For $n = 1 To $avPath[0] $sTestPath &= $avPath[$n] $hFound = _GUICtrlTreeView_FindItemEx($hTV1, $sTestPath, 0) If $hFound = 0 Then ; Not found, add new item and set as new parent $hParent = _GUICtrlTreeView_AddChild($hTV1, $hParent, $avPath[$n]) Else ; Found, set as new parent and continue $hParent = $hFound EndIf $sTestPath &= "|" Next EndFunc Func _Quit() Exit EndFunc Happy New Year! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Nhardel Posted December 31, 2008 Author Posted December 31, 2008 WOW thanks guys I really didnt expect that much help So it does look like I was overthinking the process some. I will let you guys know how it goes. Thanks again Happy New Year to you both!!!!!!!!!
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