DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: [Still needing help]Someone please help me with treeview in this ahk script.(?)  (Read 11,657 times)

Edd

  • Participant
  • Joined in 2011
  • *
  • Posts: 2
First of all I select the Z:\ drive..
As you can see inside the Z:\ drive there are 4 Folders more: (A, B, C, J)

1.jpg

Then it will appear this window..
2.jpg
I click the "B" button..

First It will list all Folders inside "Z:\" in a text file:

5.jpg

Then it'll list all Folders inside "Z:\" that begins with "B" (remember I clicked on the "B" button before)
In this case:

7.jpg

Then it will show the content inside "Z:\B\"..

10.jpg

After that it'll create an INI document:

9.jpg

As you see the content in the INI document it's exactly the same as the content in treeview.

So the problem is..
Inside the Folder "B" there are 3 more Folders:

evi.jpg

But the Folder "audio" doesn't starts with "b" so it shouldn't be inside the Folder "B"..

What I need it's not to move the Folder "audio" but I need not to appear in the Treeview and in the INI document.
Like a loop jump when it founds a Folder not starting with "B" in this case.

This is the code of the Script.
Code: (autohotkey)

#NoEnv
FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
SplitPath,Letter,,,,,Letter ;If user select a full path instead of a drive
Letter=%Letter%\

LV_ModifyCol()
LV_Modify(0, "-Select")

TreeViewWidth := 385
; Create an ImageList and put some standard system icons into it:
ImageListID := IL_Create(5)
Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
    IL_Add(ImageListID, "shell32.dll", A_Index)
Width=413
tBarHeight=20.5
Title=Selecione el Folder :
Gui, 2:+caption +0x400000
Gui, 2:font,s10, Verdana
;---------------------------------------------------------- Title Bar & Caption Text
Gui, 2:Font, S10 Bold, Verdana
;----------------------------------------------------------- Minimize / Close Icons
Cl_IconPos:=395
Gui, 2:Color,E9E9E9
Gui, 2:Font,s8 q5, Verdana
Gui, 2:Add, Button,w14 x+1 vA, A
Gui, 2:Add, Button,w14 x+1 vB, B
Gui, 2:Add, Button,w14 x+1 vC, C
Gui, 2:Add, Button,w14 x+1 vD, D
Gui, 2:Add, Button,w14 x+1 vE, E
Gui, 2:Add, Button,w14 x+1 vF, F
Gui, 2:Add, Button,w14 x+1 vG, G
Gui, 2:Add, Button,w14 x+1 vH, H
Gui, 2:Add, Button,w14 x+1 vI, I
Gui, 2:Add, Button,w14 x+1 vJ, J
Gui, 2:Add, Button,w14 x+1 vK, K
Gui, 2:Add, Button,w14 x+1 vL, L
Gui, 2:Add, Button,w14 x+1 vM, M
Gui, 2:Add, Button,w14 x+1 vN, N
Gui, 2:Add, Button,w14 x+1 vO, O
Gui, 2:Add, Button,w14 x+1 vP, P
Gui, 2:Add, Button,w14 x+1 vQ, Q
Gui, 2:Add, Button,w14 x+1 vR, R
Gui, 2:Add, Button,w14 x+1 vS, S
Gui, 2:Add, Button,w14 x+1 vT, T
Gui, 2:Add, Button,w14 x+1 vU, U
Gui, 2:Add, Button,w14 x+1 vV, V
Gui, 2:Add, Button,w14 x+1 vW, W
Gui, 2:Add, Button,w14 x+1 vX, X
Gui, 2:Add, Button,w14 x+1 vY, Y
Gui, 2:Add, Button,w14 x+1 vZ, Z
; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
Winset, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
Gui, 2:Show, w415, Seleccione el Folder :
GuiNum=2
Loop
{
IfWinActive, Seleccione el Folder :
{
SEWIN_ID:=WinExist("A")
WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
break
}
return

Fill:
GuiControl, disable, A
GuiControl, disable, B
GuiControl, disable, C
GuiControl, disable, D
GuiControl, disable, E
GuiControl, disable, F
GuiControl, disable, G
GuiControl, disable, H
GuiControl, disable, I
GuiControl, disable, J
GuiControl, disable, K
GuiControl, disable, L
GuiControl, disable, M
GuiControl, disable, N
GuiControl, disable, O
GuiControl, disable, P
GuiControl, disable, Q
GuiControl, disable, R
GuiControl, disable, S
GuiControl, disable, T
GuiControl, disable, U
GuiControl, disable, V
GuiControl, disable, W
GuiControl, disable, X
GuiControl, disable, Y
GuiControl, disable, Z
FileDelete, %A_Temp%\PathsList.ini
Loop %Letter%\*.*, 2
{
FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
}
MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
MsgBox, 4096,,That txt document is the content on "%Letter%"
SplashTextOff
RunWait, %A_Temp%\PhList.txt
SplashTextOn, 200, 25, Cargando, Espere un momento..
Loop
{
FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
If ErrorLevel
{
FileDelete, %A_Temp%\PhList.txt
	break
	}
	StringLeft, FirstLetterOrNumber, TempFlderName, 1

If FirstLetterOrNumber=%FilterLetterOrNumber%
{
SplashTextOn, 200, 25, Cargando, Espere un momento..
FileAppend,
(
%Letter%%TempFlderName%`n
),%A_Temp%\PathList.txt,UTF-8
}
}
IfExist, %A_Temp%\PathList.txt
{
MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
SplashTextOff
RunWait, %A_Temp%\PathList.txt
SplashTextOn, 200, 25, Cargando, Espere un momento..
}
else
{
SplashTextOff
MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
MsgBox, 4096,,Try with other letter...
Goto, Guishow
}
Loop
{
IfExist, %A_Temp%\PathList.txt
{
FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
If ErrorLevel
{
FileDelete, %A_Temp%\PathList.txt
	break
	}
AddSubFoldersToTree(TreeRoot)

AddSubFoldersToTree(Folder, ParentItemID = 0)
{
    ; This function adds to the TreeView all subfolders in the specified folder.
    ; It also calls itself recursively to gather nested folders to any depth.
    Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
		  TV_Modify(0, "Sort")
/*
		  Already2=1
		  If Already2!=
		  {
		  Already2:=
TV_GetText(OutputVarName, ParentItemID)
StringLeft, OutFirstChar, OutputVarName,1
IfNotInString, OutFirstChar, %FilterLetterOrNumber%
{
TV_Delete(ParentItemID)
}
}
*/
		If ParentItemID!=0
		IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
}
}
}
SplashTextOff
IfExist, %A_Temp%\PathsList.ini
{
MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
RunWait, %A_Temp%\PathsList.ini
}
else
MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
SplashTextOff
Guishow:
Gui, 2:Show,, Seleccione el Folder :
GuiControl, enable, A
GuiControl, enable, B
GuiControl, enable, C
GuiControl, enable, D
GuiControl, enable, E
GuiControl, enable, F
GuiControl, enable, G
GuiControl, enable, H
GuiControl, enable, I
GuiControl, enable, J
GuiControl, enable, K
GuiControl, enable, L
GuiControl, enable, M
GuiControl, enable, N
GuiControl, enable, O
GuiControl, enable, P
GuiControl, enable, Q
GuiControl, enable, R
GuiControl, enable, S
GuiControl, enable, T
GuiControl, enable, U
GuiControl, enable, V
GuiControl, enable, W
GuiControl, enable, X
GuiControl, enable, Y
GuiControl, enable, Z
return


MyTreeLabel:  ; This subroutine handles user actions (such as clicking).
FileDelete, %A_Temp%\List.txt
if A_GuiEvent <> S
return
lns=0
SoundPlay, 0
Sng:=
		TV_GetText(SelectedItemText, A_EventInfo)
		ItemText=%SelectedItemText%
ParentID := A_EventInfo
Loop  ; Build the full path to the selected folder.
{
If MainGuiLeft=0
break
    ParentID := TV_GetParent(ParentID)
    if not ParentID  ; No more ancestors.
        break
    TV_GetText(ParentText, ParentID)
    SelectedItemText = %ParentText%\%SelectedItemText%
}
sel := TV_GetSelection()
IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
return

2ButtonA:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=A
Goto, Fill
return
2ButtonB:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=B
Goto, Fill
return
2ButtonC:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=C
Goto, Fill
return
2ButtonD:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=D
Goto, Fill
return
2ButtonE:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=E
Goto, Fill
return
2ButtonF:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=F
Goto, Fill
return
2ButtonG:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=G
Goto, Fill
return
2ButtonH:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=H
Goto, Fill
return
2ButtonI:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=I
Goto, Fill
return
2ButtonJ:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=J
Goto, Fill
return
2ButtonK:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=K
Goto, Fill
return
2ButtonL:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=L
Goto, Fill
return
2ButtonM:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=M
Goto, Fill
return
2ButtonN:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=N
Goto, Fill
return
2ButtonO:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=O
Goto, Fill
return
2ButtonP:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=P
Goto, Fill
return
2ButtonQ:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=Q
Goto, Fill
return
2ButtonR:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=R
Goto, Fill
return
2ButtonS:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=S
Goto, Fill
return
2ButtonT:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=T
Goto, Fill
return
2ButtonU:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=U
Goto, Fill
return
2ButtonV:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=V
Goto, Fill
return
2ButtonW:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=W
Goto, Fill
return
2ButtonX:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=X
Goto, Fill
return
2ButtonY:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=Y
Goto, Fill
return
2ButtonZ:
TV_Delete()
FileDelete, %A_Temp%\List.txt
FilterLetterOrNumber=Z
Goto, Fill
return

}
return

Close:
IfWinNotExist, Cargando
{
GuiControl, %GuiNum%:Hide, Button_Close1
If GuiNum=2
{
2GuiClose:
If Looping=
{
FileDelete, %A_Temp%\PathsList.ini
FileDelete, %A_Temp%\PhList.txt
FileDelete, %A_Temp%\PathList.txt

SplashTextOff
Gui 2:Destroy
MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
ExitApp
}
}
}
return

Note:
To run it and test it you will need to create the folders like an example the ones are in the images.

« Last Edit: January 02, 2012, 03:17 PM by Edd »

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: Could someone please help me with treeview in this ahk script?
« Reply #1 on: December 31, 2011, 01:31 PM »
If I understand you correctly, in order to only add folders beginning with the initial you have clicked you need to add another parameter to the AddSubFoldersToTree function passing the initial, then use that to start the loop:

AddSubFoldersToTree(Folder, ParentItemID = 0, Initial)
{
   ; This function adds to the TreeView all subfolders in the specified folder.
   ; It also calls itself recursively to gather nested folders to any depth.
   Loop %Folder%\%Initial%*.*, 2  ; Retrieve all of Folder's sub-folders.
   {
       AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
 TV_Modify(0, "Sort")
}
If ParentItemID!=0
IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
}

This is assuming you are recreating the treeview everytime you press the button.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Could someone please help me with treeview in this ahk script?
« Reply #2 on: December 31, 2011, 02:21 PM »
I simplified a few things where you were duplicating a lot of code when using the whole alphabet.  You'll see what I mean.  Also, I tried to clean up and indent your code a bit.  I'm not a fan of including labels/functions within other labels/functions so, if you would like, I can clean it up much further than this.  Here you go:

Code: (autohotkey)
#NoEnv
FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
Letter=%Letter%\

LV_ModifyCol()
LV_Modify(0, "-Select")

TreeViewWidth := 385
; Create an ImageList and put some standard system icons into it:
ImageListID := IL_Create(5)
Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
    IL_Add(ImageListID, "shell32.dll", A_Index)
Width=413
tBarHeight=20.5
Title=Selecione el Folder :
Gui, 2:+Caption +0x400000
Gui, 2:font,s10, Verdana
;---------------------------------------------------------- Title Bar & Caption Text
Gui, 2:Font, S10 Bold, Verdana
;----------------------------------------------------------- Minimize / Close Icons
Cl_IconPos:=395
Gui, 2:Color,E9E9E9
Gui, 2:Font,s8 q5, Verdana
Loop, 26
{
    Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
}
; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
Gui, 2:Show, w415, Seleccione el Folder :
GuiNum=2
Loop
{
    IfWinActive, Seleccione el Folder :
    {
        SEWIN_ID:=WinExist("A")
        WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
        Break
    }
    Return

Fill:
    Loop, 26
    {
        GuiControl, Disable, % Chr( 64 + A_Index )
    }
    FileDelete, %A_Temp%\PathsList.ini
    Loop %Letter%\*.*, 2
    {
        FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
    }
    MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
    MsgBox, 4096,,That txt document is the content on "%Letter%"
    SplashTextOff
    RunWait, %A_Temp%\PhList.txt
    SplashTextOn, 200, 25, Cargando, Espere un momento..
    Loop
    {
        FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
        If ErrorLevel
        {
            FileDelete, %A_Temp%\PhList.txt
            Break
        }
        StringLeft, FirstLetterOrNumber, TempFlderName, 1

        If FirstLetterOrNumber=%FilterLetterOrNumber%
        {
            SplashTextOn, 200, 25, Cargando, Espere un momento..
            FileAppend,
            (
%Letter%%TempFlderName%`n
            ),%A_Temp%\PathList.txt,UTF-8
        }
    }
    IfExist, %A_Temp%\PathList.txt
    {
        MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
        SplashTextOff
        RunWait, %A_Temp%\PathList.txt
        SplashTextOn, 200, 25, Cargando, Espere un momento..
    }
    Else
    {
        SplashTextOff
        MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
        MsgBox, 4096,,Try with other letter...
        Goto, Guishow
    }
    Loop
    {
        IfExist, %A_Temp%\PathList.txt
        {
            FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
            If ErrorLevel
            {
                FileDelete, %A_Temp%\PathList.txt
                Break
            }
            AddSubFoldersToTree(TreeRoot)

            AddSubFoldersToTree(Folder, ParentItemID = 0)
            {
                ; This function adds to the TreeView all subfolders in the specified folder.
                ; It also calls itself recursively to gather nested folders to any depth.
                Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
                {
                    If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
                    {
                        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
                    }
                }
                TV_Modify(0, "Sort")
                If ParentItemID!=0
                    IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
            }
        }
    }
SplashTextOff
IfExist, %A_Temp%\PathsList.ini
{
    MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
    RunWait, %A_Temp%\PathsList.ini
}
Else
    MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
SplashTextOff
Guishow:
    Gui, 2:Show,, Seleccione el Folder :
    Loop, 26
    {
        GuiControl, Enable, % Chr( 64 + A_Index )
    }
Return


MyTreeLabel:  ; This subroutine handles user actions (such as clicking).
    FileDelete, %A_Temp%\List.txt
    If A_GuiEvent <> S
        Return
    lns=0
    SoundPlay, 0
    Sng:=
    TV_GetText(SelectedItemText, A_EventInfo)
    ItemText=%SelectedItemText%
    ParentID := A_EventInfo
    Loop  ; Build the full path to the selected folder.
    {
        If MainGuiLeft=0
            Break
        ParentID := TV_GetParent(ParentID)
        If not ParentID  ; No more ancestors.
            Break
        TV_GetText(ParentText, ParentID)
        SelectedItemText = %ParentText%\%SelectedItemText%
    }
    sel := TV_GetSelection()
    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
Return

2ButtonA:
2ButtonB:
2ButtonC:
2ButtonD:
2ButtonE:
2ButtonF:
2ButtonG:
2ButtonH:
2ButtonI:
2ButtonJ:
2ButtonK:
2ButtonL:
2ButtonM:
2ButtonN:
2ButtonO:
2ButtonP:
2ButtonQ:
2ButtonR:
2ButtonS:
2ButtonT:
2ButtonU:
2ButtonV:
2ButtonW:
2ButtonX:
2ButtonY:
2ButtonZ:
    TV_Delete()
    FileDelete, %A_Temp%\List.txt
    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
    Goto, Fill
Return
Return

}
Return

Close:
    IfWinNotExist, Cargando
    {
        GuiControl, %GuiNum%:Hide, Button_Close1
        If GuiNum=2
        {
        2GuiClose:
            If Looping=
            {
                FileDelete, %A_Temp%\PathsList.ini
                FileDelete, %A_Temp%\PhList.txt
                FileDelete, %A_Temp%\PathList.txt
        
                SplashTextOff
                Gui 2:Destroy
                MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
                ExitApp
            }
        }
}
Return

Edd

  • Participant
  • Joined in 2011
  • *
  • Posts: 2
Re: Could someone please help me with treeview in this ahk script?
« Reply #3 on: December 31, 2011, 10:17 PM »
I simplified a few things where you were duplicating a lot of code when using the whole alphabet.  You'll see what I mean.  Also, I tried to clean up and indent your code a bit.  I'm not a fan of including labels/functions within other labels/functions so, if you would like, I can clean it up much further than this.  Here you go:

Code: (autohotkey)
#NoEnv
FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
Letter=%Letter%\

LV_ModifyCol()
LV_Modify(0, "-Select")

TreeViewWidth := 385
; Create an ImageList and put some standard system icons into it:
ImageListID := IL_Create(5)
Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
    IL_Add(ImageListID, "shell32.dll", A_Index)
Width=413
tBarHeight=20.5
Title=Selecione el Folder :
Gui, 2:+Caption +0x400000
Gui, 2:font,s10, Verdana
;---------------------------------------------------------- Title Bar & Caption Text
Gui, 2:Font, S10 Bold, Verdana
;----------------------------------------------------------- Minimize / Close Icons
Cl_IconPos:=395
Gui, 2:Color,E9E9E9
Gui, 2:Font,s8 q5, Verdana
Loop, 26
{
    Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
}
; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
Gui, 2:Show, w415, Seleccione el Folder :
GuiNum=2
Loop
{
    IfWinActive, Seleccione el Folder :
    {
        SEWIN_ID:=WinExist("A")
        WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
        Break
    }
    Return

Fill:
    Loop, 26
    {
        GuiControl, Disable, % Chr( 64 + A_Index )
    }
    FileDelete, %A_Temp%\PathsList.ini
    Loop %Letter%\*.*, 2
    {
        FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
    }
    MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
    MsgBox, 4096,,That txt document is the content on "%Letter%"
    SplashTextOff
    RunWait, %A_Temp%\PhList.txt
    SplashTextOn, 200, 25, Cargando, Espere un momento..
    Loop
    {
        FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
        If ErrorLevel
        {
            FileDelete, %A_Temp%\PhList.txt
            Break
        }
        StringLeft, FirstLetterOrNumber, TempFlderName, 1

        If FirstLetterOrNumber=%FilterLetterOrNumber%
        {
            SplashTextOn, 200, 25, Cargando, Espere un momento..
            FileAppend,
            (
%Letter%%TempFlderName%`n
            ),%A_Temp%\PathList.txt,UTF-8
        }
    }
    IfExist, %A_Temp%\PathList.txt
    {
        MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
        SplashTextOff
        RunWait, %A_Temp%\PathList.txt
        SplashTextOn, 200, 25, Cargando, Espere un momento..
    }
    Else
    {
        SplashTextOff
        MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
        MsgBox, 4096,,Try with other letter...
        Goto, Guishow
    }
    Loop
    {
        IfExist, %A_Temp%\PathList.txt
        {
            FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
            If ErrorLevel
            {
                FileDelete, %A_Temp%\PathList.txt
                Break
            }
            AddSubFoldersToTree(TreeRoot)

            AddSubFoldersToTree(Folder, ParentItemID = 0)
            {
                ; This function adds to the TreeView all subfolders in the specified folder.
                ; It also calls itself recursively to gather nested folders to any depth.
                Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
                {
                    If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
                    {
                        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
                    }
                }
                TV_Modify(0, "Sort")
                If ParentItemID!=0
                    IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
            }
        }
    }
SplashTextOff
IfExist, %A_Temp%\PathsList.ini
{
    MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
    RunWait, %A_Temp%\PathsList.ini
}
Else
    MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
SplashTextOff
Guishow:
    Gui, 2:Show,, Seleccione el Folder :
    Loop, 26
    {
        GuiControl, Enable, % Chr( 64 + A_Index )
    }
Return


MyTreeLabel:  ; This subroutine handles user actions (such as clicking).
    FileDelete, %A_Temp%\List.txt
    If A_GuiEvent <> S
        Return
    lns=0
    SoundPlay, 0
    Sng:=
    TV_GetText(SelectedItemText, A_EventInfo)
    ItemText=%SelectedItemText%
    ParentID := A_EventInfo
    Loop  ; Build the full path to the selected folder.
    {
        If MainGuiLeft=0
            Break
        ParentID := TV_GetParent(ParentID)
        If not ParentID  ; No more ancestors.
            Break
        TV_GetText(ParentText, ParentID)
        SelectedItemText = %ParentText%\%SelectedItemText%
    }
    sel := TV_GetSelection()
    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
Return

2ButtonA:
2ButtonB:
2ButtonC:
2ButtonD:
2ButtonE:
2ButtonF:
2ButtonG:
2ButtonH:
2ButtonI:
2ButtonJ:
2ButtonK:
2ButtonL:
2ButtonM:
2ButtonN:
2ButtonO:
2ButtonP:
2ButtonQ:
2ButtonR:
2ButtonS:
2ButtonT:
2ButtonU:
2ButtonV:
2ButtonW:
2ButtonX:
2ButtonY:
2ButtonZ:
    TV_Delete()
    FileDelete, %A_Temp%\List.txt
    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
    Goto, Fill
Return
Return

}
Return

Close:
    IfWinNotExist, Cargando
    {
        GuiControl, %GuiNum%:Hide, Button_Close1
        If GuiNum=2
        {
        2GuiClose:
            If Looping=
            {
                FileDelete, %A_Temp%\PathsList.ini
                FileDelete, %A_Temp%\PhList.txt
                FileDelete, %A_Temp%\PathList.txt
        
                SplashTextOff
                Gui 2:Destroy
                MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
                ExitApp
            }
        }
}
Return


skwire that makes nearly what i need, but stills having problem, I added a "#" button too, but it should show all full path in the treeview and sometimes only appear the first folder but not all the subfolders
Also I added the folders structure and the Z: virtual drive to test it.
Check it

This is the new code:

Code: (autohotkey)
#NoEnv
/*
FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
Letter=%Letter%\
*/

;Creating virtual drive
{
VLetter=Z
FileCreateDir, C:\%VLetter%
FileSetAttrib, +H, C:\%VLetter%
RunWait, %ComSpec% /c subst %VLetter%: C:\%VLetter%,,hide
FileCreateDir, %VLetter%:\2212\123\Folder for test 1
FileCreateDir, %VLetter%:\5796\987\Folder for test 2
FileCreateDir, %VLetter%:\A\Alejandro Fernandez\Viento a Favor
FileCreateDir, %VLetter%:\B\audio
FileCreateDir, %VLetter%:\B\Bigsun Rock\BS
FileCreateDir, %VLetter%:\B\Blink 182\Greatest Hits
FileCreateDir, %VLetter%:\C\Test Folder
FileCreateDir, %VLetter%:\J\Jotdog\Jotdog
}
Letter=Z:\

LV_ModifyCol()
LV_Modify(0, "-Select")

TreeViewWidth := 385
; Create an ImageList and put some standard system icons into it:
ImageListID := IL_Create(5)
Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
    IL_Add(ImageListID, "shell32.dll", A_Index)
Width=413
tBarHeight=20.5
Title=Selecione el Folder :
Gui, 2:+Caption +0x400000
Gui, 2:font,s10, Verdana
;---------------------------------------------------------- Title Bar & Caption Text
Gui, 2:Font, S10 Bold, Verdana
;----------------------------------------------------------- Minimize / Close Icons
Cl_IconPos:=395
Gui, 2:Color,E9E9E9
Gui, 2:Font,s8 q5, Verdana
Gui, 2:Add, Button,x5 w14 v#, #
Loop, 26
{
    Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
}
; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
Gui, 2:Show, w415, Seleccione el Folder :
GuiNum=2
Loop
{
    IfWinActive, Seleccione el Folder :
    {
        SEWIN_ID:=WinExist("A")
        WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
        Break
    }
    Return

Fill:
GuiControl, disable, #
    Loop, 26
    {
        GuiControl, Disable, % Chr( 64 + A_Index )
    }
    FileDelete, %A_Temp%\PathsList.ini
    Loop %Letter%\*.*, 2
    {
        FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
    }
    MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
    MsgBox, 4096,,That txt document is the content on "%Letter%"
    SplashTextOff
    RunWait, %A_Temp%\PhList.txt
    SplashTextOn, 200, 25, Cargando, Espere un momento..
    Loop
    {
        FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
        If ErrorLevel
        {
            FileDelete, %A_Temp%\PhList.txt
            Break
        }
        StringLeft, FirstLetterOrNumber, TempFlderName, 1
If FilterLetterOrNumber=#
{
	If FirstLetterOrNumber is digit ;Si la variable esta ocupada de caracteres numericos
{
SplashTextOn, 200, 25, Cargando, Espere un momento..
FileAppend,
(
%Letter%%TempFlderName%`n
),%A_Temp%\PathList.txt,UTF-8
}
}
		else
		{
        If FirstLetterOrNumber=%FilterLetterOrNumber%
        {
            SplashTextOn, 200, 25, Cargando, Espere un momento..
            FileAppend,
            (
%Letter%%TempFlderName%`n
            ),%A_Temp%\PathList.txt,UTF-8
        }
		}
    }
    IfExist, %A_Temp%\PathList.txt
    {
        MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
        SplashTextOff
        RunWait, %A_Temp%\PathList.txt
        SplashTextOn, 200, 25, Cargando, Espere un momento..
    }
    Else
    {
        SplashTextOff
        MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
        MsgBox, 4096,,Try with other letter...
        Goto, Guishow
    }
    Loop
    {
        IfExist, %A_Temp%\PathList.txt
        {
            FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
            If ErrorLevel
            {
                FileDelete, %A_Temp%\PathList.txt
                Break
            }
            AddSubFoldersToTree(TreeRoot)

            AddSubFoldersToTree(Folder, ParentItemID = 0)
            {
                ; This function adds to the TreeView all subfolders in the specified folder.
                ; It also calls itself recursively to gather nested folders to any depth.
                Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
                {
                    If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
                    {
                        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
                    }
                }
                TV_Modify(0, "Sort")
                If ParentItemID!=0
                    IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
            }
        }
    }
SplashTextOff
IfExist, %A_Temp%\PathsList.ini
{
    MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
    RunWait, %A_Temp%\PathsList.ini
}
Else
   MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
SplashTextOff
Guishow:
    Gui, 2:Show,, Seleccione el Folder :
	GuiControl, Enable, #
    Loop, 26
    {
        GuiControl, Enable, % Chr( 64 + A_Index )
    }
Return


MyTreeLabel:  ; This subroutine handles user actions (such as clicking).
    FileDelete, %A_Temp%\List.txt
    If A_GuiEvent <> S
        Return
    lns=0
    SoundPlay, 0
    Sng:=
    TV_GetText(SelectedItemText, A_EventInfo)
    ItemText=%SelectedItemText%
    ParentID := A_EventInfo
    Loop  ; Build the full path to the selected folder.
    {
        If MainGuiLeft=0
            Break
        ParentID := TV_GetParent(ParentID)
        If not ParentID  ; No more ancestors.
            Break
        TV_GetText(ParentText, ParentID)
        SelectedItemText = %ParentText%\%SelectedItemText%
    }
    sel := TV_GetSelection()
    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
Return
2Button#:
2ButtonA:
2ButtonB:
2ButtonC:
2ButtonD:
2ButtonE:
2ButtonF:
2ButtonG:
2ButtonH:
2ButtonI:
2ButtonJ:
2ButtonK:
2ButtonL:
2ButtonM:
2ButtonN:
2ButtonO:
2ButtonP:
2ButtonQ:
2ButtonR:
2ButtonS:
2ButtonT:
2ButtonU:
2ButtonV:
2ButtonW:
2ButtonX:
2ButtonY:
2ButtonZ:
    TV_Delete()
    FileDelete, %A_Temp%\List.txt
    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
    Goto, Fill
Return
Return

}
Return

Close:
    IfWinNotExist, Cargando
    {
        GuiControl, %GuiNum%:Hide, Button_Close1
        If GuiNum=2
        {
        2GuiClose:
            If Looping=
            {
                FileDelete, %A_Temp%\PathsList.ini
                FileDelete, %A_Temp%\PhList.txt
                FileDelete, %A_Temp%\PathList.txt
				
        ;Erasing virual drive
{
FileSetAttrib, -H, C:\%VLetter%
RunWait, %ComSpec% /c subst %VLetter%: /D,,hide
FileRemoveDir, C:\%VLetter%, 1
}

                SplashTextOff
                Gui 2:Destroy
                MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
                ExitApp
            }
        }
}
Return

« Last Edit: January 02, 2012, 12:09 AM by Edd »

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 626
    • Participated in NANY Challenge Once
Re: Could someone please help me with treeview in this ahk script?
« Reply #4 on: January 01, 2012, 06:25 PM »
Have you guys thought about having a teach-your-self-paced-AHK school/sub-forum?  I think there used to be one here a long time ago.  I've tried teaching myself off and on over the years, it's pretty hard to wrap your brain around though if you have had no formal instruction.  I can make a script that will type out the date...  That's about it.

jgpaiva

  • Artificial Idiocy
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • Cody Award
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Portugal Inhabitant
    • Linux User
Re: Could someone please help me with treeview in this ahk script?
« Reply #5 on: January 02, 2012, 11:39 AM »
Have you guys thought about having a teach-your-self-paced-AHK school/sub-forum?  I think there used to be one here a long time ago.
I think you're looking for this ;)

Original address: https://www.donationcoder.com/forum/index.php?topic=29469.0