Sign in to follow this  
Followers 0
photonbuddy

Files/Folders in listviews

2 posts in this topic

Trying to think of an appropriate title for this was hard ;)

I am writing a project that deals with multiple folders and files stored in a database. This database may have 10's of thousands of entries in it, each line holding the full path of a filename.

I have worked through most of the problems, but am hitting a bit of a wall with this one.

After reading of the 4096 entry limit of a listview, I decided to change the way this section of the program is handled.

This part of the program is designed to allow the user to select files and add them to a favorites list.

Initially, everything was working pretty good using _GUICtrlListViewCopyItems, but once I loaded-up the database with ~15,000 files, that no longer worked (and took me an hour to figure it out).

Now, I have re-designed the window to have a listview that lists the folders, then a listview to then list the files in that folder, and finally a listview for the favorites. After selecting 1 or more entries from the files listview, the user hits a button, and the favorites listview is updated accordingly.

The code so far generates a list of folders by running through the array holding the filenames, sorts the array, and then removes the duplicate folder's (this needs to be done because of the way the database is sorted).

The problem I have now is determining that the user has clicked an item in the folders listview. I initially thought that GUIGetMsg() would return an event to say that something had occured within the listview, but it appears that selecting an item doesn't generate a message.

I did some reading on here, and saw the suggestion of using the $GUI_EVENT_PRIMARYDOWN flag, But that seems a little over-the-top, seeing as how the user might not even be clicking in the listview.

Does anyone have any ideas on how to get around this?

Or, any ideas on a better way to structure this routine?

Share this post


Link to post
Share on other sites



one idea

#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

8)

two just to read a selection in a treeview

; read the selection
$item1 = GUICtrlRead($treeview)
$item2 = GUICtrlRead($item1, 1)

hope those help

8)


NEWHeader1.png

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  
Followers 0