ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

[Still needing help]Someone please help me with treeview in this ahk script.(?)

(1/2) > >>

Edd:
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)



Then it will appear this window..

I click the "B" button..

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



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



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



After that it'll create an INI document:



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:



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 ---#NoEnvFileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your DriveSplitPath,Letter,,,,,Letter ;If user select a full path instead of a driveLetter=%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=413tBarHeight=20.5Title=Selecione el Folder :Gui, 2:+caption +0x400000Gui, 2:font,s10, Verdana;---------------------------------------------------------- Title Bar & Caption TextGui, 2:Font, S10 Bold, Verdana;----------------------------------------------------------- Minimize / Close IconsCl_IconPos:=395Gui, 2:Color,E9E9E9Gui, 2:Font,s8 q5, VerdanaGui, 2:Add, Button,w14 x+1 vA, AGui, 2:Add, Button,w14 x+1 vB, BGui, 2:Add, Button,w14 x+1 vC, CGui, 2:Add, Button,w14 x+1 vD, DGui, 2:Add, Button,w14 x+1 vE, EGui, 2:Add, Button,w14 x+1 vF, FGui, 2:Add, Button,w14 x+1 vG, GGui, 2:Add, Button,w14 x+1 vH, HGui, 2:Add, Button,w14 x+1 vI, IGui, 2:Add, Button,w14 x+1 vJ, JGui, 2:Add, Button,w14 x+1 vK, KGui, 2:Add, Button,w14 x+1 vL, LGui, 2:Add, Button,w14 x+1 vM, MGui, 2:Add, Button,w14 x+1 vN, NGui, 2:Add, Button,w14 x+1 vO, OGui, 2:Add, Button,w14 x+1 vP, PGui, 2:Add, Button,w14 x+1 vQ, QGui, 2:Add, Button,w14 x+1 vR, RGui, 2:Add, Button,w14 x+1 vS, SGui, 2:Add, Button,w14 x+1 vT, TGui, 2:Add, Button,w14 x+1 vU, UGui, 2:Add, Button,w14 x+1 vV, VGui, 2:Add, Button,w14 x+1 vW, WGui, 2:Add, Button,w14 x+1 vX, XGui, 2:Add, Button,w14 x+1 vY, YGui, 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=2Loop{IfWinActive, Seleccione el Folder :{SEWIN_ID:=WinExist("A")WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%break}return Fill:GuiControl, disable, AGuiControl, disable, BGuiControl, disable, CGuiControl, disable, DGuiControl, disable, EGuiControl, disable, FGuiControl, disable, GGuiControl, disable, HGuiControl, disable, IGuiControl, disable, JGuiControl, disable, KGuiControl, disable, LGuiControl, disable, MGuiControl, disable, NGuiControl, disable, OGuiControl, disable, PGuiControl, disable, QGuiControl, disable, RGuiControl, disable, SGuiControl, disable, TGuiControl, disable, UGuiControl, disable, VGuiControl, disable, WGuiControl, disable, XGuiControl, disable, YGuiControl, disable, ZFileDelete, %A_Temp%\PathsList.iniLoop %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%"SplashTextOffRunWait, %A_Temp%\PhList.txtSplashTextOn, 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...SplashTextOffRunWait, %A_Temp%\PathList.txtSplashTextOn, 200, 25, Cargando, Espere un momento..}else{SplashTextOffMsgBox, 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,1IfNotInString, OutFirstChar, %FilterLetterOrNumber%{TV_Delete(ParentItemID)}}*/                If ParentItemID!=0                IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%}}}SplashTextOffIfExist, %A_Temp%\PathsList.ini{MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...RunWait, %A_Temp%\PathsList.ini}elseMsgBox, 4096,,The founded root(s) doesn't contain folders to add...SplashTextOffGuishow:Gui, 2:Show,, Seleccione el Folder :GuiControl, enable, AGuiControl, enable, BGuiControl, enable, CGuiControl, enable, DGuiControl, enable, EGuiControl, enable, FGuiControl, enable, GGuiControl, enable, HGuiControl, enable, IGuiControl, enable, JGuiControl, enable, KGuiControl, enable, LGuiControl, enable, MGuiControl, enable, NGuiControl, enable, OGuiControl, enable, PGuiControl, enable, QGuiControl, enable, RGuiControl, enable, SGuiControl, enable, TGuiControl, enable, UGuiControl, enable, VGuiControl, enable, WGuiControl, enable, XGuiControl, enable, YGuiControl, enable, Zreturn  MyTreeLabel: ; This subroutine handles user actions (such as clicking).FileDelete, %A_Temp%\List.txtif A_GuiEvent <> Sreturnlns=0SoundPlay, 0Sng:=                TV_GetText(SelectedItemText, A_EventInfo)                ItemText=%SelectedItemText%ParentID := A_EventInfoLoop  ; Build the full path to the selected folder.{If MainGuiLeft=0break    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.txtFilterLetterOrNumber=AGoto, Fillreturn2ButtonB:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=BGoto, Fillreturn2ButtonC:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=CGoto, Fillreturn2ButtonD:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=DGoto, Fillreturn2ButtonE:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=EGoto, Fillreturn2ButtonF:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=FGoto, Fillreturn2ButtonG:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=GGoto, Fillreturn2ButtonH:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=HGoto, Fillreturn2ButtonI:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=IGoto, Fillreturn2ButtonJ:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=JGoto, Fillreturn2ButtonK:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=KGoto, Fillreturn2ButtonL:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=LGoto, Fillreturn2ButtonM:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=MGoto, Fillreturn2ButtonN:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=NGoto, Fillreturn2ButtonO:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=OGoto, Fillreturn2ButtonP:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=PGoto, Fillreturn2ButtonQ:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=QGoto, Fillreturn2ButtonR:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=RGoto, Fillreturn2ButtonS:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=SGoto, Fillreturn2ButtonT:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=TGoto, Fillreturn2ButtonU:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=UGoto, Fillreturn2ButtonV:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=VGoto, Fillreturn2ButtonW:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=WGoto, Fillreturn2ButtonX:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=XGoto, Fillreturn2ButtonY:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=YGoto, Fillreturn2ButtonZ:TV_Delete()FileDelete, %A_Temp%\List.txtFilterLetterOrNumber=ZGoto, Fillreturn }return Close:IfWinNotExist, Cargando{GuiControl, %GuiNum%:Hide, Button_Close1If GuiNum=2{2GuiClose:If Looping={FileDelete, %A_Temp%\PathsList.iniFileDelete, %A_Temp%\PhList.txtFileDelete, %A_Temp%\PathList.txt SplashTextOffGui 2:DestroyMsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5ExitApp}}}return
Note:
To run it and test it you will need to create the folders like an example the ones are in the images.

justice:
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 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 ---#NoEnvFileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your DriveSplitPath,Letter,,,,,Letter ;If user select a full path instead of a DriveLetter=%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=413tBarHeight=20.5Title=Selecione el Folder :Gui, 2:+Caption +0x400000Gui, 2:font,s10, Verdana;---------------------------------------------------------- Title Bar & Caption TextGui, 2:Font, S10 Bold, Verdana;----------------------------------------------------------- Minimize / Close IconsCl_IconPos:=395Gui, 2:Color,E9E9E9Gui, 2:Font,s8 q5, VerdanaLoop, 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=2Loop{    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%            }        }    }SplashTextOffIfExist, %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...SplashTextOffGuishow:    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, FillReturnReturn }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:
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 ---#NoEnvFileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your DriveSplitPath,Letter,,,,,Letter ;If user select a full path instead of a DriveLetter=%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=413tBarHeight=20.5Title=Selecione el Folder :Gui, 2:+Caption +0x400000Gui, 2:font,s10, Verdana;---------------------------------------------------------- Title Bar & Caption TextGui, 2:Font, S10 Bold, Verdana;----------------------------------------------------------- Minimize / Close IconsCl_IconPos:=395Gui, 2:Color,E9E9E9Gui, 2:Font,s8 q5, VerdanaLoop, 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=2Loop{    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%            }        }    }SplashTextOffIfExist, %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...SplashTextOffGuishow:    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, FillReturnReturn }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 (December 31, 2011, 08:21 AM)
--- End quote ---


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 DriveSplitPath,Letter,,,,,Letter ;If user select a full path instead of a DriveLetter=%Letter%\*/ ;Creating virtual drive{VLetter=ZFileCreateDir, C:\%VLetter%FileSetAttrib, +H, C:\%VLetter%RunWait, %ComSpec% /c subst %VLetter%: C:\%VLetter%,,hideFileCreateDir, %VLetter%:\2212\123\Folder for test 1FileCreateDir, %VLetter%:\5796\987\Folder for test 2FileCreateDir, %VLetter%:\A\Alejandro Fernandez\Viento a FavorFileCreateDir, %VLetter%:\B\audioFileCreateDir, %VLetter%:\B\Bigsun Rock\BSFileCreateDir, %VLetter%:\B\Blink 182\Greatest HitsFileCreateDir, %VLetter%:\C\Test FolderFileCreateDir, %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=413tBarHeight=20.5Title=Selecione el Folder :Gui, 2:+Caption +0x400000Gui, 2:font,s10, Verdana;---------------------------------------------------------- Title Bar & Caption TextGui, 2:Font, S10 Bold, Verdana;----------------------------------------------------------- Minimize / Close IconsCl_IconPos:=395Gui, 2:Color,E9E9E9Gui, 2:Font,s8 q5, VerdanaGui, 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=2Loop{    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, 1If 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%            }        }    }SplashTextOffIfExist, %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...SplashTextOffGuishow:    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%Return2Button#: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, FillReturnReturn }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,,hideFileRemoveDir, C:\%VLetter%, 1}                 SplashTextOff                Gui 2:Destroy                MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5                ExitApp            }        }}Return

kunkel321:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version