Website Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • August 31, 2015, 01:47:14 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

Edd

  • Participant
  • Joined in 2011
  • *
  • gravatar avatar
  • Posts: 2
    • View Profile
    • Donate to Member
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
  1.  
  2. FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
  3. SplitPath,Letter,,,,,Letter ;If user select a full path instead of a drive
  4. Letter=%Letter%\
  5.  
  6. LV_Modify(0, "-Select")
  7.  
  8. TreeViewWidth := 385
  9. ; Create an ImageList and put some standard system icons into it:
  10. ImageListID := IL_Create(5)
  11. Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
  12.     IL_Add(ImageListID, "shell32.dll", A_Index)
  13. Width=413
  14. tBarHeight=20.5
  15. Title=Selecione el Folder :
  16. Gui, 2:+caption +0x400000
  17. Gui, 2:font,s10, Verdana
  18. ;---------------------------------------------------------- Title Bar & Caption Text
  19. Gui, 2:Font, S10 Bold, Verdana
  20. ;----------------------------------------------------------- Minimize / Close Icons
  21. Cl_IconPos:=395
  22. Gui, 2:Color,E9E9E9
  23. Gui, 2:Font,s8 q5, Verdana
  24. Gui, 2:Add, Button,w14 x+1 vA, A
  25. Gui, 2:Add, Button,w14 x+1 vB, B
  26. Gui, 2:Add, Button,w14 x+1 vC, C
  27. Gui, 2:Add, Button,w14 x+1 vD, D
  28. Gui, 2:Add, Button,w14 x+1 vE, E
  29. Gui, 2:Add, Button,w14 x+1 vF, F
  30. Gui, 2:Add, Button,w14 x+1 vG, G
  31. Gui, 2:Add, Button,w14 x+1 vH, H
  32. Gui, 2:Add, Button,w14 x+1 vI, I
  33. Gui, 2:Add, Button,w14 x+1 vJ, J
  34. Gui, 2:Add, Button,w14 x+1 vK, K
  35. Gui, 2:Add, Button,w14 x+1 vL, L
  36. Gui, 2:Add, Button,w14 x+1 vM, M
  37. Gui, 2:Add, Button,w14 x+1 vN, N
  38. Gui, 2:Add, Button,w14 x+1 vO, O
  39. Gui, 2:Add, Button,w14 x+1 vP, P
  40. Gui, 2:Add, Button,w14 x+1 vQ, Q
  41. Gui, 2:Add, Button,w14 x+1 vR, R
  42. Gui, 2:Add, Button,w14 x+1 vS, S
  43. Gui, 2:Add, Button,w14 x+1 vT, T
  44. Gui, 2:Add, Button,w14 x+1 vU, U
  45. Gui, 2:Add, Button,w14 x+1 vV, V
  46. Gui, 2:Add, Button,w14 x+1 vW, W
  47. Gui, 2:Add, Button,w14 x+1 vX, X
  48. Gui, 2:Add, Button,w14 x+1 vY, Y
  49. Gui, 2:Add, Button,w14 x+1 vZ, Z
  50. ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
  51. Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
  52. SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
  53. Winset, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
  54. Gui, 2:Show, w415, Seleccione el Folder :
  55. GuiNum=2
  56. {
  57. IfWinActive, Seleccione el Folder :
  58. {
  59. SEWIN_ID:=WinExist("A")
  60. WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
  61. }
  62. return
  63.  
  64. Fill:
  65. GuiControl, disable, A
  66. GuiControl, disable, B
  67. GuiControl, disable, C
  68. GuiControl, disable, D
  69. GuiControl, disable, E
  70. GuiControl, disable, F
  71. GuiControl, disable, G
  72. GuiControl, disable, H
  73. GuiControl, disable, I
  74. GuiControl, disable, J
  75. GuiControl, disable, K
  76. GuiControl, disable, L
  77. GuiControl, disable, M
  78. GuiControl, disable, N
  79. GuiControl, disable, O
  80. GuiControl, disable, P
  81. GuiControl, disable, Q
  82. GuiControl, disable, R
  83. GuiControl, disable, S
  84. GuiControl, disable, T
  85. GuiControl, disable, U
  86. GuiControl, disable, V
  87. GuiControl, disable, W
  88. GuiControl, disable, X
  89. GuiControl, disable, Y
  90. GuiControl, disable, Z
  91. FileDelete, %A_Temp%\PathsList.ini
  92. Loop %Letter%\*.*, 2
  93. {
  94. FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
  95. }
  96. MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
  97. MsgBox, 4096,,That txt document is the content on "%Letter%"
  98. RunWait, %A_Temp%\PhList.txt
  99. SplashTextOn, 200, 25, Cargando, Espere un momento..
  100. {
  101. FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
  102. {
  103. FileDelete, %A_Temp%\PhList.txt
  104.         break
  105.         }
  106.         StringLeft, FirstLetterOrNumber, TempFlderName, 1
  107.  
  108. If FirstLetterOrNumber=%FilterLetterOrNumber%
  109. {
  110. SplashTextOn, 200, 25, Cargando, Espere un momento..
  111. (
  112. %Letter%%TempFlderName%`n
  113. ),%A_Temp%\PathList.txt,UTF-8
  114. }
  115. }
  116. IfExist, %A_Temp%\PathList.txt
  117. {
  118. MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  119. RunWait, %A_Temp%\PathList.txt
  120. SplashTextOn, 200, 25, Cargando, Espere un momento..
  121. }
  122. else
  123. {
  124. MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  125. MsgBox, 4096,,Try with other letter...
  126. Goto, Guishow
  127. }
  128. {
  129. IfExist, %A_Temp%\PathList.txt
  130. {
  131. FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  132. {
  133. FileDelete, %A_Temp%\PathList.txt
  134.         break
  135.         }
  136. AddSubFoldersToTree(TreeRoot)
  137.  
  138. AddSubFoldersToTree(Folder, ParentItemID = 0)
  139. {
  140.     ; This function adds to the TreeView all subfolders in the specified folder.
  141.     ; It also calls itself recursively to gather nested folders to any depth.
  142.     Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  143.         AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  144.                   TV_Modify(0, "Sort")
  145. /*
  146.                   Already2=1
  147.                   If Already2!=
  148.                   {
  149.                   Already2:=
  150. TV_GetText(OutputVarName, ParentItemID)
  151. StringLeft, OutFirstChar, OutputVarName,1
  152. IfNotInString, OutFirstChar, %FilterLetterOrNumber%
  153. {
  154. TV_Delete(ParentItemID)
  155. }
  156. }
  157. */
  158.                 If ParentItemID!=0
  159.                 IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  160. }
  161. }
  162. }
  163. IfExist, %A_Temp%\PathsList.ini
  164. {
  165. MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  166. RunWait, %A_Temp%\PathsList.ini
  167. }
  168. else
  169. MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  170. Guishow:
  171. Gui, 2:Show,, Seleccione el Folder :
  172. GuiControl, enable, A
  173. GuiControl, enable, B
  174. GuiControl, enable, C
  175. GuiControl, enable, D
  176. GuiControl, enable, E
  177. GuiControl, enable, F
  178. GuiControl, enable, G
  179. GuiControl, enable, H
  180. GuiControl, enable, I
  181. GuiControl, enable, J
  182. GuiControl, enable, K
  183. GuiControl, enable, L
  184. GuiControl, enable, M
  185. GuiControl, enable, N
  186. GuiControl, enable, O
  187. GuiControl, enable, P
  188. GuiControl, enable, Q
  189. GuiControl, enable, R
  190. GuiControl, enable, S
  191. GuiControl, enable, T
  192. GuiControl, enable, U
  193. GuiControl, enable, V
  194. GuiControl, enable, W
  195. GuiControl, enable, X
  196. GuiControl, enable, Y
  197. GuiControl, enable, Z
  198. return
  199.  
  200.  
  201. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  202. FileDelete, %A_Temp%\List.txt
  203. if A_GuiEvent <> S
  204. return
  205. lns=0
  206. Sng:=
  207.                 TV_GetText(SelectedItemText, A_EventInfo)
  208.                 ItemText=%SelectedItemText%
  209. ParentID := A_EventInfo
  210. Loop  ; Build the full path to the selected folder.
  211. {
  212. If MainGuiLeft=0
  213.     ParentID := TV_GetParent(ParentID)
  214.     if not ParentID  ; No more ancestors.
  215.         break
  216.     TV_GetText(ParentText, ParentID)
  217.     SelectedItemText = %ParentText%\%SelectedItemText%
  218. }
  219. IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  220. return
  221.  
  222. 2ButtonA:
  223. FileDelete, %A_Temp%\List.txt
  224. FilterLetterOrNumber=A
  225. Goto, Fill
  226. return
  227. 2ButtonB:
  228. FileDelete, %A_Temp%\List.txt
  229. FilterLetterOrNumber=B
  230. Goto, Fill
  231. return
  232. 2ButtonC:
  233. FileDelete, %A_Temp%\List.txt
  234. FilterLetterOrNumber=C
  235. Goto, Fill
  236. return
  237. 2ButtonD:
  238. FileDelete, %A_Temp%\List.txt
  239. FilterLetterOrNumber=D
  240. Goto, Fill
  241. return
  242. 2ButtonE:
  243. FileDelete, %A_Temp%\List.txt
  244. FilterLetterOrNumber=E
  245. Goto, Fill
  246. return
  247. 2ButtonF:
  248. FileDelete, %A_Temp%\List.txt
  249. FilterLetterOrNumber=F
  250. Goto, Fill
  251. return
  252. 2ButtonG:
  253. FileDelete, %A_Temp%\List.txt
  254. FilterLetterOrNumber=G
  255. Goto, Fill
  256. return
  257. 2ButtonH:
  258. FileDelete, %A_Temp%\List.txt
  259. FilterLetterOrNumber=H
  260. Goto, Fill
  261. return
  262. 2ButtonI:
  263. FileDelete, %A_Temp%\List.txt
  264. FilterLetterOrNumber=I
  265. Goto, Fill
  266. return
  267. 2ButtonJ:
  268. FileDelete, %A_Temp%\List.txt
  269. FilterLetterOrNumber=J
  270. Goto, Fill
  271. return
  272. 2ButtonK:
  273. FileDelete, %A_Temp%\List.txt
  274. FilterLetterOrNumber=K
  275. Goto, Fill
  276. return
  277. 2ButtonL:
  278. FileDelete, %A_Temp%\List.txt
  279. FilterLetterOrNumber=L
  280. Goto, Fill
  281. return
  282. 2ButtonM:
  283. FileDelete, %A_Temp%\List.txt
  284. FilterLetterOrNumber=M
  285. Goto, Fill
  286. return
  287. 2ButtonN:
  288. FileDelete, %A_Temp%\List.txt
  289. FilterLetterOrNumber=N
  290. Goto, Fill
  291. return
  292. 2ButtonO:
  293. FileDelete, %A_Temp%\List.txt
  294. FilterLetterOrNumber=O
  295. Goto, Fill
  296. return
  297. 2ButtonP:
  298. FileDelete, %A_Temp%\List.txt
  299. FilterLetterOrNumber=P
  300. Goto, Fill
  301. return
  302. 2ButtonQ:
  303. FileDelete, %A_Temp%\List.txt
  304. FilterLetterOrNumber=Q
  305. Goto, Fill
  306. return
  307. 2ButtonR:
  308. FileDelete, %A_Temp%\List.txt
  309. FilterLetterOrNumber=R
  310. Goto, Fill
  311. return
  312. 2ButtonS:
  313. FileDelete, %A_Temp%\List.txt
  314. FilterLetterOrNumber=S
  315. Goto, Fill
  316. return
  317. 2ButtonT:
  318. FileDelete, %A_Temp%\List.txt
  319. FilterLetterOrNumber=T
  320. Goto, Fill
  321. return
  322. 2ButtonU:
  323. FileDelete, %A_Temp%\List.txt
  324. FilterLetterOrNumber=U
  325. Goto, Fill
  326. return
  327. 2ButtonV:
  328. FileDelete, %A_Temp%\List.txt
  329. FilterLetterOrNumber=V
  330. Goto, Fill
  331. return
  332. 2ButtonW:
  333. FileDelete, %A_Temp%\List.txt
  334. FilterLetterOrNumber=W
  335. Goto, Fill
  336. return
  337. 2ButtonX:
  338. FileDelete, %A_Temp%\List.txt
  339. FilterLetterOrNumber=X
  340. Goto, Fill
  341. return
  342. 2ButtonY:
  343. FileDelete, %A_Temp%\List.txt
  344. FilterLetterOrNumber=Y
  345. Goto, Fill
  346. return
  347. 2ButtonZ:
  348. FileDelete, %A_Temp%\List.txt
  349. FilterLetterOrNumber=Z
  350. Goto, Fill
  351. return
  352.  
  353. }
  354. return
  355.  
  356. Close:
  357. IfWinNotExist, Cargando
  358. {
  359. GuiControl, %GuiNum%:Hide, Button_Close1
  360. If GuiNum=2
  361. {
  362. 2GuiClose:
  363. If Looping=
  364. {
  365. FileDelete, %A_Temp%\PathsList.ini
  366. FileDelete, %A_Temp%\PhList.txt
  367. FileDelete, %A_Temp%\PathList.txt
  368.  
  369. MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
  370. }
  371. }
  372. }
  373. return
  374.  

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, 09:17:31 AM by Edd »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #1 on: December 31, 2011, 07:31:28 AM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,391
    • View Profile
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #2 on: December 31, 2011, 08:21:55 AM »
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
  1. FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
  2. SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
  3. Letter=%Letter%\
  4.  
  5. LV_Modify(0, "-Select")
  6.  
  7. TreeViewWidth := 385
  8. ; Create an ImageList and put some standard system icons into it:
  9. ImageListID := IL_Create(5)
  10. Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
  11.     IL_Add(ImageListID, "shell32.dll", A_Index)
  12. Width=413
  13. tBarHeight=20.5
  14. Title=Selecione el Folder :
  15. Gui, 2:+Caption +0x400000
  16. Gui, 2:font,s10, Verdana
  17. ;---------------------------------------------------------- Title Bar & Caption Text
  18. Gui, 2:Font, S10 Bold, Verdana
  19. ;----------------------------------------------------------- Minimize / Close Icons
  20. Cl_IconPos:=395
  21. Gui, 2:Color,E9E9E9
  22. Gui, 2:Font,s8 q5, Verdana
  23. Loop, 26
  24. {
  25.     Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
  26. }
  27. ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
  28. Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
  29. SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
  30. WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
  31. Gui, 2:Show, w415, Seleccione el Folder :
  32. GuiNum=2
  33. {
  34.     IfWinActive, Seleccione el Folder :
  35.     {
  36.         SEWIN_ID:=WinExist("A")
  37.         WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
  38.         Break
  39.     }
  40.     Return
  41.  
  42. Fill:
  43.    Loop, 26
  44.     {
  45.         GuiControl, Disable, % Chr( 64 + A_Index )
  46.     }
  47.     FileDelete, %A_Temp%\PathsList.ini
  48.     Loop %Letter%\*.*, 2
  49.     {
  50.         FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
  51.     }
  52.     MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
  53.     MsgBox, 4096,,That txt document is the content on "%Letter%"
  54.     RunWait, %A_Temp%\PhList.txt
  55.     SplashTextOn, 200, 25, Cargando, Espere un momento..
  56.     Loop
  57.     {
  58.         FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
  59.         If ErrorLevel
  60.         {
  61.             FileDelete, %A_Temp%\PhList.txt
  62.             Break
  63.         }
  64.         StringLeft, FirstLetterOrNumber, TempFlderName, 1
  65.  
  66.         If FirstLetterOrNumber=%FilterLetterOrNumber%
  67.         {
  68.             SplashTextOn, 200, 25, Cargando, Espere un momento..
  69.             FileAppend,
  70.             (
  71. %Letter%%TempFlderName%`n
  72.             ),%A_Temp%\PathList.txt,UTF-8
  73.         }
  74.     }
  75.     IfExist, %A_Temp%\PathList.txt
  76.     {
  77.         MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  78.         SplashTextOff
  79.         RunWait, %A_Temp%\PathList.txt
  80.         SplashTextOn, 200, 25, Cargando, Espere un momento..
  81.     }
  82.     Else
  83.     {
  84.         SplashTextOff
  85.         MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  86.         MsgBox, 4096,,Try with other letter...
  87.         Goto, Guishow
  88.     }
  89.     Loop
  90.     {
  91.         IfExist, %A_Temp%\PathList.txt
  92.         {
  93.             FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  94.             If ErrorLevel
  95.             {
  96.                 FileDelete, %A_Temp%\PathList.txt
  97.                 Break
  98.             }
  99.             AddSubFoldersToTree(TreeRoot)
  100.  
  101.             AddSubFoldersToTree(Folder, ParentItemID = 0)
  102.             {
  103.                 ; This function adds to the TreeView all subfolders in the specified folder.
  104.                 ; It also calls itself recursively to gather nested folders to any depth.
  105.                 Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  106.                 {
  107.                     If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
  108.                     {
  109.                         AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  110.                     }
  111.                 }
  112.                 TV_Modify(0, "Sort")
  113.                 If ParentItemID!=0
  114.                     IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  115.             }
  116.         }
  117.     }
  118. IfExist, %A_Temp%\PathsList.ini
  119. {
  120.     MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  121.     RunWait, %A_Temp%\PathsList.ini
  122. }
  123. Else
  124.     MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  125. Guishow:
  126.    Gui, 2:Show,, Seleccione el Folder :
  127.     Loop, 26
  128.     {
  129.         GuiControl, Enable, % Chr( 64 + A_Index )
  130.     }
  131. Return
  132.  
  133.  
  134. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  135.     FileDelete, %A_Temp%\List.txt
  136.     If A_GuiEvent <> S
  137.         Return
  138.     lns=0
  139.     SoundPlay, 0
  140.     Sng:=
  141.     TV_GetText(SelectedItemText, A_EventInfo)
  142.     ItemText=%SelectedItemText%
  143.     ParentID := A_EventInfo
  144.     Loop  ; Build the full path to the selected folder.
  145.     {
  146.         If MainGuiLeft=0
  147.             Break
  148.         ParentID := TV_GetParent(ParentID)
  149.         If not ParentID  ; No more ancestors.
  150.             Break
  151.         TV_GetText(ParentText, ParentID)
  152.         SelectedItemText = %ParentText%\%SelectedItemText%
  153.     }
  154.     sel := TV_GetSelection()
  155.     IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  156. Return
  157.  
  158. 2ButtonA:
  159. 2ButtonB:
  160. 2ButtonC:
  161. 2ButtonD:
  162. 2ButtonE:
  163. 2ButtonF:
  164. 2ButtonG:
  165. 2ButtonH:
  166. 2ButtonI:
  167. 2ButtonJ:
  168. 2ButtonK:
  169. 2ButtonL:
  170. 2ButtonM:
  171. 2ButtonN:
  172. 2ButtonO:
  173. 2ButtonP:
  174. 2ButtonQ:
  175. 2ButtonR:
  176. 2ButtonS:
  177. 2ButtonT:
  178. 2ButtonU:
  179. 2ButtonV:
  180. 2ButtonW:
  181. 2ButtonX:
  182. 2ButtonY:
  183. 2ButtonZ:
  184.    TV_Delete()
  185.     FileDelete, %A_Temp%\List.txt
  186.     StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  187.     Goto, Fill
  188. Return
  189. Return
  190.  
  191. }
  192. Return
  193.  
  194. Close:
  195.    IfWinNotExist, Cargando
  196.     {
  197.         GuiControl, %GuiNum%:Hide, Button_Close1
  198.         If GuiNum=2
  199.         {
  200.         2GuiClose:
  201.            If Looping=
  202.             {
  203.                 FileDelete, %A_Temp%\PathsList.ini
  204.                 FileDelete, %A_Temp%\PhList.txt
  205.                 FileDelete, %A_Temp%\PathList.txt
  206.        
  207.                 SplashTextOff
  208.                 Gui 2:Destroy
  209.                 MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
  210.                 ExitApp
  211.             }
  212.         }
  213. }
  214. Return
  215.  
  216.  

Edd

  • Participant
  • Joined in 2011
  • *
  • gravatar avatar
  • Posts: 2
    • View Profile
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #3 on: December 31, 2011, 04:17: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
  1. FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
  2. SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
  3. Letter=%Letter%\
  4.  
  5. LV_Modify(0, "-Select")
  6.  
  7. TreeViewWidth := 385
  8. ; Create an ImageList and put some standard system icons into it:
  9. ImageListID := IL_Create(5)
  10. Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
  11.     IL_Add(ImageListID, "shell32.dll", A_Index)
  12. Width=413
  13. tBarHeight=20.5
  14. Title=Selecione el Folder :
  15. Gui, 2:+Caption +0x400000
  16. Gui, 2:font,s10, Verdana
  17. ;---------------------------------------------------------- Title Bar & Caption Text
  18. Gui, 2:Font, S10 Bold, Verdana
  19. ;----------------------------------------------------------- Minimize / Close Icons
  20. Cl_IconPos:=395
  21. Gui, 2:Color,E9E9E9
  22. Gui, 2:Font,s8 q5, Verdana
  23. Loop, 26
  24. {
  25.     Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
  26. }
  27. ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
  28. Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
  29. SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
  30. WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
  31. Gui, 2:Show, w415, Seleccione el Folder :
  32. GuiNum=2
  33. {
  34.     IfWinActive, Seleccione el Folder :
  35.     {
  36.         SEWIN_ID:=WinExist("A")
  37.         WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
  38.         Break
  39.     }
  40.     Return
  41.  
  42. Fill:
  43.    Loop, 26
  44.     {
  45.         GuiControl, Disable, % Chr( 64 + A_Index )
  46.     }
  47.     FileDelete, %A_Temp%\PathsList.ini
  48.     Loop %Letter%\*.*, 2
  49.     {
  50.         FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
  51.     }
  52.     MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
  53.     MsgBox, 4096,,That txt document is the content on "%Letter%"
  54.     RunWait, %A_Temp%\PhList.txt
  55.     SplashTextOn, 200, 25, Cargando, Espere un momento..
  56.     Loop
  57.     {
  58.         FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
  59.         If ErrorLevel
  60.         {
  61.             FileDelete, %A_Temp%\PhList.txt
  62.             Break
  63.         }
  64.         StringLeft, FirstLetterOrNumber, TempFlderName, 1
  65.  
  66.         If FirstLetterOrNumber=%FilterLetterOrNumber%
  67.         {
  68.             SplashTextOn, 200, 25, Cargando, Espere un momento..
  69.             FileAppend,
  70.             (
  71. %Letter%%TempFlderName%`n
  72.             ),%A_Temp%\PathList.txt,UTF-8
  73.         }
  74.     }
  75.     IfExist, %A_Temp%\PathList.txt
  76.     {
  77.         MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  78.         SplashTextOff
  79.         RunWait, %A_Temp%\PathList.txt
  80.         SplashTextOn, 200, 25, Cargando, Espere un momento..
  81.     }
  82.     Else
  83.     {
  84.         SplashTextOff
  85.         MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  86.         MsgBox, 4096,,Try with other letter...
  87.         Goto, Guishow
  88.     }
  89.     Loop
  90.     {
  91.         IfExist, %A_Temp%\PathList.txt
  92.         {
  93.             FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  94.             If ErrorLevel
  95.             {
  96.                 FileDelete, %A_Temp%\PathList.txt
  97.                 Break
  98.             }
  99.             AddSubFoldersToTree(TreeRoot)
  100.  
  101.             AddSubFoldersToTree(Folder, ParentItemID = 0)
  102.             {
  103.                 ; This function adds to the TreeView all subfolders in the specified folder.
  104.                 ; It also calls itself recursively to gather nested folders to any depth.
  105.                 Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  106.                 {
  107.                     If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
  108.                     {
  109.                         AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  110.                     }
  111.                 }
  112.                 TV_Modify(0, "Sort")
  113.                 If ParentItemID!=0
  114.                     IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  115.             }
  116.         }
  117.     }
  118. IfExist, %A_Temp%\PathsList.ini
  119. {
  120.     MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  121.     RunWait, %A_Temp%\PathsList.ini
  122. }
  123. Else
  124.     MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  125. Guishow:
  126.    Gui, 2:Show,, Seleccione el Folder :
  127.     Loop, 26
  128.     {
  129.         GuiControl, Enable, % Chr( 64 + A_Index )
  130.     }
  131. Return
  132.  
  133.  
  134. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  135.     FileDelete, %A_Temp%\List.txt
  136.     If A_GuiEvent <> S
  137.         Return
  138.     lns=0
  139.     SoundPlay, 0
  140.     Sng:=
  141.     TV_GetText(SelectedItemText, A_EventInfo)
  142.     ItemText=%SelectedItemText%
  143.     ParentID := A_EventInfo
  144.     Loop  ; Build the full path to the selected folder.
  145.     {
  146.         If MainGuiLeft=0
  147.             Break
  148.         ParentID := TV_GetParent(ParentID)
  149.         If not ParentID  ; No more ancestors.
  150.             Break
  151.         TV_GetText(ParentText, ParentID)
  152.         SelectedItemText = %ParentText%\%SelectedItemText%
  153.     }
  154.     sel := TV_GetSelection()
  155.     IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  156. Return
  157.  
  158. 2ButtonA:
  159. 2ButtonB:
  160. 2ButtonC:
  161. 2ButtonD:
  162. 2ButtonE:
  163. 2ButtonF:
  164. 2ButtonG:
  165. 2ButtonH:
  166. 2ButtonI:
  167. 2ButtonJ:
  168. 2ButtonK:
  169. 2ButtonL:
  170. 2ButtonM:
  171. 2ButtonN:
  172. 2ButtonO:
  173. 2ButtonP:
  174. 2ButtonQ:
  175. 2ButtonR:
  176. 2ButtonS:
  177. 2ButtonT:
  178. 2ButtonU:
  179. 2ButtonV:
  180. 2ButtonW:
  181. 2ButtonX:
  182. 2ButtonY:
  183. 2ButtonZ:
  184.    TV_Delete()
  185.     FileDelete, %A_Temp%\List.txt
  186.     StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  187.     Goto, Fill
  188. Return
  189. Return
  190.  
  191. }
  192. Return
  193.  
  194. Close:
  195.    IfWinNotExist, Cargando
  196.     {
  197.         GuiControl, %GuiNum%:Hide, Button_Close1
  198.         If GuiNum=2
  199.         {
  200.         2GuiClose:
  201.            If Looping=
  202.             {
  203.                 FileDelete, %A_Temp%\PathsList.ini
  204.                 FileDelete, %A_Temp%\PhList.txt
  205.                 FileDelete, %A_Temp%\PathList.txt
  206.        
  207.                 SplashTextOff
  208.                 Gui 2:Destroy
  209.                 MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
  210.                 ExitApp
  211.             }
  212.         }
  213. }
  214. Return
  215.  
  216.  


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
  1. /*
  2. FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
  3. SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
  4. Letter=%Letter%\
  5. */
  6.  
  7. ;Creating virtual drive
  8. {
  9. VLetter=Z
  10. FileCreateDir, C:\%VLetter%
  11. FileSetAttrib, +H, C:\%VLetter%
  12. RunWait, %ComSpec% /c subst %VLetter%: C:\%VLetter%,,hide
  13. FileCreateDir, %VLetter%:\2212\123\Folder for test 1
  14. FileCreateDir, %VLetter%:\5796\987\Folder for test 2
  15. FileCreateDir, %VLetter%:\A\Alejandro Fernandez\Viento a Favor
  16. FileCreateDir, %VLetter%:\B\audio
  17. FileCreateDir, %VLetter%:\B\Bigsun Rock\BS
  18. FileCreateDir, %VLetter%:\B\Blink 182\Greatest Hits
  19. FileCreateDir, %VLetter%:\C\Test Folder
  20. FileCreateDir, %VLetter%:\J\Jotdog\Jotdog
  21. }
  22. Letter=Z:\
  23.  
  24. LV_Modify(0, "-Select")
  25.  
  26. TreeViewWidth := 385
  27. ; Create an ImageList and put some standard system icons into it:
  28. ImageListID := IL_Create(5)
  29. Loop 5  ; Below omits the DLL's path so that it works on Windows 9x too:
  30.     IL_Add(ImageListID, "shell32.dll", A_Index)
  31. Width=413
  32. tBarHeight=20.5
  33. Title=Selecione el Folder :
  34. Gui, 2:+Caption +0x400000
  35. Gui, 2:font,s10, Verdana
  36. ;---------------------------------------------------------- Title Bar & Caption Text
  37. Gui, 2:Font, S10 Bold, Verdana
  38. ;----------------------------------------------------------- Minimize / Close Icons
  39. Cl_IconPos:=395
  40. Gui, 2:Color,E9E9E9
  41. Gui, 2:Font,s8 q5, Verdana
  42. Gui, 2:Add, Button,x5 w14 v#, #
  43. Loop, 26
  44. {
  45.     Gui, 2:Add, Button,% "w14 x+1 v" . Chr( 64 + A_Index ), % Chr( 64 + A_Index )
  46. }
  47. ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
  48. Gui, 2:Add, TreeView, vMyTree x15 r20 w%TreeViewWidth% gMyTreeLabel ImageList%ImageListID%
  49. SB_SetParts(60, 85)  ; Create three parts in the bar (the third part fills all the remaining width).
  50. WinSet, AlwaysOnTop, OFF, ahk_id %SEWIN_ID%
  51. Gui, 2:Show, w415, Seleccione el Folder :
  52. GuiNum=2
  53. {
  54.     IfWinActive, Seleccione el Folder :
  55.     {
  56.         SEWIN_ID:=WinExist("A")
  57.         WinGet, ExStyle, ExStyle, ahk_id %SEWIN_ID%
  58.         Break
  59.     }
  60.     Return
  61.  
  62. Fill:
  63. GuiControl, disable, #
  64.     Loop, 26
  65.     {
  66.         GuiControl, Disable, % Chr( 64 + A_Index )
  67.     }
  68.     FileDelete, %A_Temp%\PathsList.ini
  69.     Loop %Letter%\*.*, 2
  70.     {
  71.         FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
  72.     }
  73.     MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
  74.     MsgBox, 4096,,That txt document is the content on "%Letter%"
  75.     RunWait, %A_Temp%\PhList.txt
  76.     SplashTextOn, 200, 25, Cargando, Espere un momento..
  77.     Loop
  78.     {
  79.         FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
  80.         If ErrorLevel
  81.         {
  82.             FileDelete, %A_Temp%\PhList.txt
  83.             Break
  84.         }
  85.         StringLeft, FirstLetterOrNumber, TempFlderName, 1
  86. If FilterLetterOrNumber=#
  87. {
  88.         If FirstLetterOrNumber is digit ;Si la variable esta ocupada de caracteres numericos
  89. {
  90. SplashTextOn, 200, 25, Cargando, Espere un momento..
  91. (
  92. %Letter%%TempFlderName%`n
  93. ),%A_Temp%\PathList.txt,UTF-8
  94. }
  95. }
  96.                 else
  97.                 {
  98.         If FirstLetterOrNumber=%FilterLetterOrNumber%
  99.         {
  100.             SplashTextOn, 200, 25, Cargando, Espere un momento..
  101.             FileAppend,
  102.             (
  103. %Letter%%TempFlderName%`n
  104.             ),%A_Temp%\PathList.txt,UTF-8
  105.         }
  106.                 }
  107.     }
  108.     IfExist, %A_Temp%\PathList.txt
  109.     {
  110.         MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  111.         SplashTextOff
  112.         RunWait, %A_Temp%\PathList.txt
  113.         SplashTextOn, 200, 25, Cargando, Espere un momento..
  114.     }
  115.     Else
  116.     {
  117.         SplashTextOff
  118.         MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  119.         MsgBox, 4096,,Try with other letter...
  120.         Goto, Guishow
  121.     }
  122.     Loop
  123.     {
  124.         IfExist, %A_Temp%\PathList.txt
  125.         {
  126.             FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  127.             If ErrorLevel
  128.             {
  129.                 FileDelete, %A_Temp%\PathList.txt
  130.                 Break
  131.             }
  132.             AddSubFoldersToTree(TreeRoot)
  133.  
  134.             AddSubFoldersToTree(Folder, ParentItemID = 0)
  135.             {
  136.                 ; This function adds to the TreeView all subfolders in the specified folder.
  137.                 ; It also calls itself recursively to gather nested folders to any depth.
  138.                 Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  139.                 {
  140.                     If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
  141.                     {
  142.                         AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  143.                     }
  144.                 }
  145.                 TV_Modify(0, "Sort")
  146.                 If ParentItemID!=0
  147.                     IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  148.             }
  149.         }
  150.     }
  151. IfExist, %A_Temp%\PathsList.ini
  152. {
  153.     MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  154.     RunWait, %A_Temp%\PathsList.ini
  155. }
  156. Else
  157.    MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  158. Guishow:
  159.    Gui, 2:Show,, Seleccione el Folder :
  160.         GuiControl, Enable, #
  161.     Loop, 26
  162.     {
  163.         GuiControl, Enable, % Chr( 64 + A_Index )
  164.     }
  165. Return
  166.  
  167.  
  168. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  169.     FileDelete, %A_Temp%\List.txt
  170.     If A_GuiEvent <> S
  171.         Return
  172.     lns=0
  173.     SoundPlay, 0
  174.     Sng:=
  175.     TV_GetText(SelectedItemText, A_EventInfo)
  176.     ItemText=%SelectedItemText%
  177.     ParentID := A_EventInfo
  178.     Loop  ; Build the full path to the selected folder.
  179.     {
  180.         If MainGuiLeft=0
  181.             Break
  182.         ParentID := TV_GetParent(ParentID)
  183.         If not ParentID  ; No more ancestors.
  184.             Break
  185.         TV_GetText(ParentText, ParentID)
  186.         SelectedItemText = %ParentText%\%SelectedItemText%
  187.     }
  188.     sel := TV_GetSelection()
  189.     IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  190. Return
  191. 2Button#:
  192. 2ButtonA:
  193. 2ButtonB:
  194. 2ButtonC:
  195. 2ButtonD:
  196. 2ButtonE:
  197. 2ButtonF:
  198. 2ButtonG:
  199. 2ButtonH:
  200. 2ButtonI:
  201. 2ButtonJ:
  202. 2ButtonK:
  203. 2ButtonL:
  204. 2ButtonM:
  205. 2ButtonN:
  206. 2ButtonO:
  207. 2ButtonP:
  208. 2ButtonQ:
  209. 2ButtonR:
  210. 2ButtonS:
  211. 2ButtonT:
  212. 2ButtonU:
  213. 2ButtonV:
  214. 2ButtonW:
  215. 2ButtonX:
  216. 2ButtonY:
  217. 2ButtonZ:
  218.    TV_Delete()
  219.     FileDelete, %A_Temp%\List.txt
  220.     StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  221.     Goto, Fill
  222. Return
  223. Return
  224.  
  225. }
  226. Return
  227.  
  228. Close:
  229.    IfWinNotExist, Cargando
  230.     {
  231.         GuiControl, %GuiNum%:Hide, Button_Close1
  232.         If GuiNum=2
  233.         {
  234.         2GuiClose:
  235.            If Looping=
  236.             {
  237.                 FileDelete, %A_Temp%\PathsList.ini
  238.                 FileDelete, %A_Temp%\PhList.txt
  239.                 FileDelete, %A_Temp%\PathList.txt
  240.                                
  241.         ;Erasing virual drive
  242. {
  243. FileSetAttrib, -H, C:\%VLetter%
  244. RunWait, %ComSpec% /c subst %VLetter%: /D,,hide
  245. FileRemoveDir, C:\%VLetter%, 1
  246. }
  247.  
  248.                 SplashTextOff
  249.                 Gui 2:Destroy
  250.                 MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
  251.                 ExitApp
  252.             }
  253.         }
  254. }
  255. Return
  256.  

« Last Edit: January 01, 2012, 06:09:25 PM by Edd »

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 428
    • View Profile
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #4 on: January 01, 2012, 12:25:50 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

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #5 on: January 02, 2012, 05:39:27 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 ;)