Jump to content

TreeView And Browsing


 Share

Recommended Posts

The last two days ive tried to make a browsing tool with TreeView.. like when browswing in regedit, this is what ive made so far. Maybe it's messy, it may not be.. give your opinion or advice to do this better.. it is not finish at all, but i can't get any further...

EDIT: Script updated - Thanks Holger

#Include <GUIConstants.au3>

Global $Tree
Global $SubTree

GUICreate("BrowseDemo",400,400)
$TreeView = GUICtrlCreateTreeView(20,20,200,300)
GUICtrlSetImage(-1,"shell32.dll",3,4)
GUICtrlSetImage(-1,"shell32.dll",4,2)

FileDelete("Files.ini")

$HDDrives = DrivegetDrive("FIXED")
For $i = 1 To $HDDrives[0]
    Search($HDDrives[$i] & "\","*.*")
    $var = IniReadSection("Files.ini", $HDDrives[$i] & "\")
    For $h = 1 To $var[0][0]
        $IniRead = IniRead("Files.ini",$HDDrives[$i] & "\",$h,"NotFound")
        _Next($IniRead,"*.*",$h)
    Next
Next    
GUISetState()


While 1;Main Loop
    $msg = GUIGetmsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd    


;Functions
;///////////////////////////////////////////
Func Search($SearchPath,$FileType)
$Item1 = GUICtrlCreateTreeViewItem(StringUpper($SearchPath),$TreeView)
GUICtrlSetImage(-1,"shell32.dll",8)
$Search = FileFindFirstFile($SearchPath & $FileType)  
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$Count = 1
DIM $Tree[99999]
While 1
    $File = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    $Attrib = FileGetAttrib($SearchPath & $File)
    If StringInStr($Attrib,"D") Then
        $Tree[$Count] = GUICtrlCreateTreeViewItem($File,$Item1)
        IniWrite("Files.ini",$SearchPath,$Count,$SearchPath & $File & "\")
        $Count = $Count +1
    EndIf
WEnd
FileClose($Search)
EndFunc



Func _Next($SearchPath,$FileType,$Number)
$Search1 = FileFindFirstFile($SearchPath & $FileType)  
If $search1 = -1 Then
Else
    $Count = 1
    DIM $SubTree[99999]
    While 1
        $NextFile = FileFindNextFile($search1) 
        If @error Then ExitLoop
        
        $Attrib = FileGetAttrib($SearchPath & $NextFile)
        If $Attrib = "D" Then;StringInStr($Attrib,"D") Then
            If $NextFile = "." Or $NextFile = ".." Then 
            Else    
                $FBuffer = $SearchPath & $NextFile & "\"
                $SubTree[$Count] = GUICtrlCreateTreeViewItem($NextFile,$Tree[$Number])
                
                $Search2 = FileFindFirstFile($FBuffer & "*.*")
                If $search2 = -1 Then
                    msgbox(0,"","Ingen mapper")
                Else
                    $Count1 = 1
                    While 1
                        $NextFile2 = FileFindNextFile($search2) 
                        If @error Then ExitLoop
                        $Attrib = FileGetAttrib($FBuffer & $NextFile2)
                        If $Attrib = "D" Then;StringInStr($Attrib,"D") Then
                            If $NextFile2 = "." Or $NextFile2 = ".." Then 
                            Else    
                                GUICtrlCreateTreeViewItem($NextFile2,$SubTree[$Count])
                                $Count1 = $Count1 +1
                            EndIf
                        EndIf
                    WEnd    
                FileClose($Search2)
                EndIf
            ;msgbox(0,"","Stop " & $Count)
                $Count = $Count +1
            EndIf
        EndIf
    WEnd    
    FileClose($Search1)
EndIf
EndFUnc
Edited by Wb-FreeKill
Link to comment
Share on other sites

Great work. I like the ini file idea.

If you were able to add the folder sizes in MB's to the ini file, I for one would find the script very useful.

<{POST_SNAPBACK}>

The idea is when you select a folder in the tree, a window at the right side should show all containing files, incl all information..

The problem is, i can't get it keep searching the folder and subfoldes until nothing is found. Then go back and proceed with the next folder in the tree until it found all the foldes (not files) and then show gui...

Any help would be great :(

Link to comment
Share on other sites

Looks very good :(

Maybe just a little bit more color with:

...
$TreeView = GUICtrlCreateTreeView(20,20,200,300)
GUICtrlSetImage(-1,"shell32.dll",3,4)
GUICtrlSetImage(-1,"shell32.dll",4,2)
...
Func Search($SearchPath,$FileType)
$Item1 = GUICtrlCreateTreeViewItem(StringUpper($SearchPath),$TreeView)
GUICtrlSetImage(-1,"shell32.dll",8)
...

Maybe I should put more energy in programming of my 'old' DirList/DirTree-project, but only after finishing the color'ed menu/icons. :

And this I only will continue it next week.

If you take a small look you can find my old sample-compiled-exe here:

http://www.hiddensoft.com/fileman/users/pu...it3Explorer.exe

So long :(

Holger

Link to comment
Share on other sites

@Wb-FreeKill: No, this is not AutoIt3-Code - it's based up 2 new controls for GUI that I started to develope some month ago (DirTree/DirList).

The last few month I didn't work on it but I will continue like I said after I finished the implementing of icons an colors in menus/menuitems for GUI/Tray :(

So long...

Link to comment
Share on other sites

@Wb-FreeKill: No, this is not AutoIt3-Code - it's based up 2 new controls for GUI that I started to develope some month ago (DirTree/DirList).

The last few month I didn't work on it but I will continue like I said after I finished the implementing of icons an colors in menus/menuitems for GUI/Tray :(

So long...

<{POST_SNAPBACK}>

okay great... :(
Link to comment
Share on other sites

Hi,

cool Script i was looking for something like that... thx!

Lets try to realize your idea:

The idea is when you select a folder in the tree, a window at the right side should show all containing files, incl all information..

When GuiCtrlRead the treeview there is the controlid of the selected Folder... (Selecting "C:\" Returns "4") When you run the search again witout creating the GUI entries it must be possible to find the folder? Hope you understand my bad english...

Here an Example (using quote, so you can see what i mean)

Func Searchagain($SearchPath,$FileType)

$Item1 = GUICtrlCreateTreeViewItem(StringUpper($SearchPath),$TreeView)

GUICtrlSetImage(-1,"shell32.dll",8)

$Search = FileFindFirstFile($SearchPath & $FileType) 

If $search = -1 Then

    MsgBox(0, "Error", "No files/directories matched the search pattern")

    Exit

EndIf

$Count = 1

DIM $Tree[99999]

While 1

    $File = FileFindNextFile($search)

    If @error Then ExitLoop

   

    $Attrib = FileGetAttrib($SearchPath & $File)

    If StringInStr($Attrib,"D") Then

        If GUICtrlRead ($treeview) = $count Then MsgBox(0,"Selected Folder",$SearchPath & $File & "\")

        IniWrite("Files.ini",$SearchPath,$Count,$SearchPath & $File & "\")

        $Count = $Count +1

    EndIf

WEnd

FileClose($Search)

EndFunc

cyclops

Sorry for my cruel english :D

Link to comment
Share on other sites

Hey,

i worked on that script and here is my version with a list for the files in selcted folder:

#Include <GUIConstants.au3>
Global $Tree
Global $SubTree
; Create GUI
GUICreate("BrowseDemo",430,325)
$TreeView = GUICtrlCreateTreeView(10,10,200,305)
GUICtrlSetImage(-1,"shell32.dll",3,4)
GUICtrlSetImage(-1,"shell32.dll",4,2)
$list = GUICtrlCreateList("",220,10,200,310)
FileDelete("Files.ini")
$test = FileOpen ("test.txt",2)
$HDDrives = DrivegetDrive("FIXED")
For $i = 1 To $HDDrives[0]
    FileWriteLine ($test,$HDDrives[$i] & "\")
    Search($HDDrives[$i] & "\","*.*")
        $var = IniReadSection("Files.ini", $HDDrives[$i] & "\")
    For $h = 1 To $var[0][0]
        $IniRead = IniRead("Files.ini",$HDDrives[$i] & "\",$h,"NotFound")
        _Next($IniRead,"*.*",$h)
    Next
Next
; Close the search handle
FileClose($test)
$test = FileOpen ("test.txt",0)
GUISetState()
$a = _Search4Files(FileReadLine ($test,GUICtrlRead ($treeview)-4))
AdlibEnable ("check")
While 1;Main Loop
    $msg = GUIGetmsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd    
Exit
;Functions
;///////////////////////////////////////////
Func Search($SearchPath,$FileType)
$Item1 = GUICtrlCreateTreeViewItem(StringUpper($SearchPath),$TreeView)
GUICtrlSetImage(-1,"shell32.dll",8)
$Search = FileFindFirstFile($SearchPath & $FileType)  
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$Count = 1
DIM $Tree[99999]
While 1
    $File = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    $Attrib = FileGetAttrib($SearchPath & $File)
    If StringInStr($Attrib,"D") Then
        $Tree[$Count] = GUICtrlCreateTreeViewItem($File,$Item1)
        FileWriteLine ($test,$SearchPath & $File & "\")
        IniWrite("Files.ini",$SearchPath,$Count,$SearchPath & $File & "\")
        $Count = $Count +1
    EndIf
WEnd
FileClose($Search)
EndFunc

Func _Next($SearchPath,$FileType,$Number)
$Search1 = FileFindFirstFile($SearchPath & $FileType)  
If $search1 = -1 Then
Else
    $Count = 1
    DIM $SubTree[99999]
    While 1
        $NextFile = FileFindNextFile($search1) 
        If @error Then ExitLoop
        
        $Attrib = FileGetAttrib($SearchPath & $NextFile)
        If $Attrib = "D" Then;StringInStr($Attrib,"D") Then
            If $NextFile = "." Or $NextFile = ".." Then 
            Else    
                $FBuffer = $SearchPath & $NextFile & "\"
                $SubTree[$Count] = GUICtrlCreateTreeViewItem($NextFile,$Tree[$Number])
                FileWriteLine ($test,$FBuffer)
                $Search2 = FileFindFirstFile($FBuffer & "*.*")
                If $search2 = -1 Then
                    msgbox(0,"","Ingen mapper")
                Else
                    $Count1 = 1
                    While 1
                        $NextFile2 = FileFindNextFile($search2) 
                        If @error Then ExitLoop
                        $Attrib = FileGetAttrib($FBuffer & $NextFile2)
                        If $Attrib = "D" Then;StringInStr($Attrib,"D") Then
                            If $NextFile2 = "." Or $NextFile2 = ".." Then 
                            Else    
                                GUICtrlCreateTreeViewItem($NextFile2,$SubTree[$Count])
                                FileWriteLine ($test,$FBuffer & $NextFile2& "\")
                                $Count1 = $Count1 +1
                            EndIf
                        EndIf
                    WEnd    
                FileClose($Search2)
                EndIf
           ;msgbox(0,"","Stop " & $Count)
                $Count = $Count +1
            EndIf
        EndIf
    WEnd    
    FileClose($Search1)
EndIf
EndFUnc

Func check()
    $b = GUICtrlRead ($treeview)
    If $a <> $b Then $a = _Search4Files(FileReadLine ($test,GUICtrlRead ($treeview)-4))
EndFunc
    
Func _Search4Files($path)
    GUICtrlSetData($list, "")
    $search4 = FileFindFirstFile($path & "*.*")  
    If $search4 <> -1 Then
        While 1
            $file = FileFindNextFile($search4) 
            If @error Then ExitLoop
            If $file = "." Then $file = FileFindNextFile($search4)
            If $file = ".." Then $file = FileFindNextFile($search4)
            If StringInStr(FileGetAttrib ($path & $file), "D") = 0 Then GUICtrlSetData($list, $file)
        WEnd
    EndIf
    Return GUICtrlRead ($treeview)
    FileClose($search4)
EndFunc

Sorry for my cruel english :D

Link to comment
Share on other sites

What do you mean? Sorry, i am a german boy ^^

Another Problem is that when a new folder is created you didn't find him in that browser until he is restarted....

Cyclops

P.S.:

I agree... Nice work. This little project keeps looking better and better. Soon you maybe could create a UDF out of it..  :(

Cheers...  :(

<{POST_SNAPBACK}>

I hope so! Edited by Cyclops

Sorry for my cruel english :D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...