topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Wednesday December 11, 2024, 12:24 pm
  • Proudly celebrating 15+ 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 9364 times)

Edd

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

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • 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 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: 5,287
    • 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 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 [Select]
  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

Edd

  • Participant
  • Joined in 2011
  • *
  • default 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 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 [Select]
  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


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 [Select]
  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

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

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 602
    • 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 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
    • Donate to Member
Re: Could someone please help me with treeview in this ahk script?
« Reply #5 on: January 02, 2012, 05: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 ;)