Jump to content
Sign in to follow this  
Wb-FreeKill

TreeView browsing - New

Recommended Posts

Started out making the treeview browsing again, it's limited bacause of no puplic treeview controls at this moment, so it's very simple!

Started this thread to get you guys opinion and ideas!

So how can i:

- Set an icon in the $sTree if it's a folder.. if file, no icon for that TreeviewItem

- Exspand all subtrees if Item is selected

EDIT: Beta is needed!

#include <GUIConstants.au3>
#include <GuiListView.au3>
Const $LVS_SORTDESCENDING = 0x0020

GUICreate("Treeview Browsing - By FreeKill",750,500)
$MainTree = GUICtrlCreateTreeView(1, 60, 250, 417)
GUICtrlSetImage(-1,"shell32.dll",3,4)
GUICtrlSetImage(-1,"shell32.dll",4,2)
$SubTree = GUICtrlCreateListview("Name|Size|Type|Changed",258, 60, 492, 417)
_GUICtrlListViewSetColumnWidth($SubTree, 0,200)
_GUICtrlListViewSetColumnWidth($SubTree, 1,100)
_GUICtrlListViewSetColumnWidth($SubTree, 2,80)
_GUICtrlListViewSetColumnWidth($SubTree, 3,100)
_GUICtrlListViewJustifyColumn ($SubTree, 1, 1)
_GUICtrlListViewJustifyColumn ($SubTree, 3, 0)
GUICtrlCreateGroup("",0,53,252,425)

$DirInput = GUICtrlCreateInput("C:\Programmer\",5,10,183,20)
$BrowseBtn = GUICtrlCreateButton("Search",193,10,60,21)
$CurrentPath = GUICtrlCreateInput(GUICtrlRead($DirInput),5,35,247,20)
GUICtrlSetState(-1,$GUI_Disable)
$ObjCount = GUICtrlCreateInput("0 Object(s)",0,480,150,20,$SS_SUNKEN)
$SpaceCount = GUICtrlCreateInput("N/A",154,480,596,20,$SS_SUNKEN)
GUISetState()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($SubTree) ]
_LoadTree(GUICtrlRead($DirInput), $MainTree,0)

; Loop
While 1
    $Msg = GUIGetMsg()
Select
    Case $Msg = $GUI_EVENT_CLOSE
        Exit

    Case $msg = $BrowseBtn 
        GUICtrlDelete($MainTree)
        $MainTree = GUICtrlCreateTreeView(1, 60, 250, 417)
        GUICtrlSetImage(-1,"shell32.dll",3,4)
        GUICtrlSetImage(-1,"shell32.dll",4,2)
        GUICtrlSetdata($CurrentPath,GUICtrlRead($DirInput))
        _LoadTree(GUICtrlRead($DirInput), $MainTree,0);Path/Tree/State
            
    Case $msg > 4 
        _GUICtrlListViewDeleteAllItems($SubTree)
        $Read = GUICtrlread($MainTree,1)
        GUICtrlSetdata($CurrentPath,GUICtrlRead($DirInput) & $Read[0] & "\")
        _LoadTree(GUICtrlRead($DirInput) & $Read[0] & "\", $SubTree,1);Path/Tree/State
        GUICtrlSetdata($ObjCount,_GUICtrlListViewGetItemCount($SubTree) & " Object(s)")
        $TheSize = DirGetSize(GUICtrlRead($Currentpath)) / 1024 / 1024
        $FreeSpace = DriveSpaceFree(Stringleft(GUICtrlRead($DirInput),3))/ 1024
        GUICtrlSetdata($SpaceCount,Stringleft($TheSize,Stringinstr($TheSize,".")+2) & " MB (Free Space: "& StringLeft($FreeSpace,StringInStr($FreeSpace,".")+1) & " GB)")
    
    Case $msg = $SubTree
        _GUICtrlListViewSort($SubTree, $B_DESCENDING, GUICtrlGetState($SubTree))

EndSelect
Wend

;                Functions
;////////////////////////////////////////////
Func _LoadTree($sRoot, $hParent, $GetFiles)
    Local $sMask = "*.*"
    Local $aFile[1], $nCnt = 1, $newParent
    Local $hSearch = FileFindFirstFile($sRoot & $sMask)
    If $hSearch >= 0 Then
       $sFile = FileFindNextFile($hSearch)
       While not @error
            ReDim $aFile[$nCnt]
            $aFile[$nCnt-1] = $sFile
            $nCnt = $nCnt + 1
            $sFile = FileFindNextFile($hSearch)
       Wend
       FileClose($hSearch)
    EndIf
    For $i = 0 To UBound($aFile) - 1
        If $aFile[$i] == "." or $aFile[$i] == ".." Then ContinueLoop
        If $GetFiles = 0 Then;Do not include files
            If StringInStr(FileGetAttrib($sRoot & "\" & $aFile[$i]), "D") Then
                $newParent = GUICtrlCreateTreeViewItem($aFile[$i], $hParent)
                _LoadTree($sRoot & $aFile[$i] & "\", $newParent,0);Keep search trough folders
                ContinueLoop
            Endif
        ElseIf $GetFiles = 1 Then;Include Files
            If StringInStr(FileGetAttrib($sRoot & "\" & $aFile[$i]), "D") Then
                $SnewParent = GUICtrlCreateListViewItem($aFile[$i], $hParent)
                ContinueLoop
            Endif
            $FilegetSize = Round(FileGetSize(GUICtrlRead($CurrentPath) & $aFile[$i]) / 1024,0) 
            $Time = FileGetTime(GUICtrlRead($CurrentPath) & $aFile[$i], 1)
            $yyyymd = $Time[2] & "." & $Time[1] & "." & $Time[0] & " " & $Time[3] & ":" & $Time[4]
            GUICtrlCreateListViewItem($aFile[$i] &"|"& $FilegetSize & " KB" &"|"& "" &"|"& $yyyymd, $hParent);Include files
        EndIf
    Next
EndFunc
Edited by Wb-FreeKill

Share this post


Link to post
Share on other sites

Can you provide an example please lol. I can't get it working. And I think you need to do some error checking because I tpye in a folder that doesn't exist and I get error's for line 86 > Time[2]


qq

Share this post


Link to post
Share on other sites

Can you provide an example please lol. I can't get it working. And I think you need to do some error checking because I tpye in a folder that doesn't exist and I get error's for line 86 > Time[2]

<{POST_SNAPBACK}>

Known bugs:

uhm, you have to change the path in the script.. and yes, if it's a non existing path, an error will popup, not yet fixed!

You can't yet select a new path after opening the script, actually same error, not fixed yet!

Only the first folder shows it's containing files and folders, not subfolders of the folder in your current path! not yet fixed eiter :(

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...