Welcome Guest.   Make a donation to an author on the site October 24, 2014, 08:27:38 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Check out and download the GOE 2007 Freeware Challenge productivity tools.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: [Still needing help]Someone please help me with treeview in this ahk script.(?)  (Read 2680 times)
Edd
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« on: December 31, 2011, 05:24:14 AM »

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.
Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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.  
  62. Fill:
  63. GuiControl, disable, A
  64. GuiControl, disable, B
  65. GuiControl, disable, C
  66. GuiControl, disable, D
  67. GuiControl, disable, E
  68. GuiControl, disable, F
  69. GuiControl, disable, G
  70. GuiControl, disable, H
  71. GuiControl, disable, I
  72. GuiControl, disable, J
  73. GuiControl, disable, K
  74. GuiControl, disable, L
  75. GuiControl, disable, M
  76. GuiControl, disable, N
  77. GuiControl, disable, O
  78. GuiControl, disable, P
  79. GuiControl, disable, Q
  80. GuiControl, disable, R
  81. GuiControl, disable, S
  82. GuiControl, disable, T
  83. GuiControl, disable, U
  84. GuiControl, disable, V
  85. GuiControl, disable, W
  86. GuiControl, disable, X
  87. GuiControl, disable, Y
  88. GuiControl, disable, Z
  89. FileDelete, %A_Temp%\PathsList.ini
  90. Loop %Letter%\*.*, 2
  91. {
  92. FileAppend, %A_LoopFileName%`n,%A_Temp%\PhList.txt,UTF-8
  93. }
  94. MsgBox, 4096,,I created a txt document named "PhList.txt", this is the content...
  95. MsgBox, 4096,,That txt document is the content on "%Letter%"
  96. RunWait, %A_Temp%\PhList.txt
  97. SplashTextOn, 200, 25, Cargando, Espere un momento..
  98. {
  99. FileReadLine, TempFlderName, %A_Temp%\PhList.txt, %A_Index%
  100. {
  101. FileDelete, %A_Temp%\PhList.txt
  102. }
  103. StringLeft, FirstLetterOrNumber, TempFlderName, 1
  104.  
  105. If FirstLetterOrNumber=%FilterLetterOrNumber%
  106. {
  107. SplashTextOn, 200, 25, Cargando, Espere un momento..
  108. (
  109. %Letter%%TempFlderName%`n
  110. ),%A_Temp%\PathList.txt,UTF-8
  111. }
  112. }
  113. IfExist, %A_Temp%\PathList.txt
  114. {
  115. MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  116. RunWait, %A_Temp%\PathList.txt
  117. SplashTextOn, 200, 25, Cargando, Espere un momento..
  118. }
  119. {
  120. MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  121. MsgBox, 4096,,Try with other letter...
  122. Goto, Guishow
  123. }
  124. {
  125. IfExist, %A_Temp%\PathList.txt
  126. {
  127. FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  128. {
  129. FileDelete, %A_Temp%\PathList.txt
  130. }
  131. AddSubFoldersToTree(TreeRoot)
  132.  
  133. AddSubFoldersToTree(Folder, ParentItemID = 0)
  134. {
  135.    ; This function adds to the TreeView all subfolders in the specified folder.
  136.    ; It also calls itself recursively to gather nested folders to any depth.
  137.    Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  138.        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  139.  TV_Modify(0, "Sort")
  140. /*
  141.  Already2=1
  142.  If Already2!=
  143.  {
  144.  Already2:=
  145. TV_GetText(OutputVarName, ParentItemID)
  146. StringLeft, OutFirstChar, OutputVarName,1
  147. IfNotInString, OutFirstChar, %FilterLetterOrNumber%
  148. {
  149. TV_Delete(ParentItemID)
  150. }
  151. }
  152. */
  153. If ParentItemID!=0
  154. IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  155. }
  156. }
  157. }
  158. IfExist, %A_Temp%\PathsList.ini
  159. {
  160. MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  161. RunWait, %A_Temp%\PathsList.ini
  162. }
  163. MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  164. Guishow:
  165. Gui, 2:Show,, Seleccione el Folder :
  166. GuiControl, enable, A
  167. GuiControl, enable, B
  168. GuiControl, enable, C
  169. GuiControl, enable, D
  170. GuiControl, enable, E
  171. GuiControl, enable, F
  172. GuiControl, enable, G
  173. GuiControl, enable, H
  174. GuiControl, enable, I
  175. GuiControl, enable, J
  176. GuiControl, enable, K
  177. GuiControl, enable, L
  178. GuiControl, enable, M
  179. GuiControl, enable, N
  180. GuiControl, enable, O
  181. GuiControl, enable, P
  182. GuiControl, enable, Q
  183. GuiControl, enable, R
  184. GuiControl, enable, S
  185. GuiControl, enable, T
  186. GuiControl, enable, U
  187. GuiControl, enable, V
  188. GuiControl, enable, W
  189. GuiControl, enable, X
  190. GuiControl, enable, Y
  191. GuiControl, enable, Z
  192.  
  193.  
  194. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  195. FileDelete, %A_Temp%\List.txt
  196. lns=0
  197. Sng:=
  198. TV_GetText(SelectedItemText, A_EventInfo)
  199. ItemText=%SelectedItemText%
  200. ParentID := A_EventInfo
  201. Loop  ; Build the full path to the selected folder.
  202. {
  203. If MainGuiLeft=0
  204.    ParentID := TV_GetParent(ParentID)
  205.    if not ParentID  ; No more ancestors.
  206.        break
  207.    TV_GetText(ParentText, ParentID)
  208.    SelectedItemText = %ParentText%\%SelectedItemText%
  209. }
  210. IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  211.  
  212. 2ButtonA:
  213. FileDelete, %A_Temp%\List.txt
  214. FilterLetterOrNumber=A
  215. Goto, Fill
  216. 2ButtonB:
  217. FileDelete, %A_Temp%\List.txt
  218. FilterLetterOrNumber=B
  219. Goto, Fill
  220. 2ButtonC:
  221. FileDelete, %A_Temp%\List.txt
  222. FilterLetterOrNumber=C
  223. Goto, Fill
  224. 2ButtonD:
  225. FileDelete, %A_Temp%\List.txt
  226. FilterLetterOrNumber=D
  227. Goto, Fill
  228. 2ButtonE:
  229. FileDelete, %A_Temp%\List.txt
  230. FilterLetterOrNumber=E
  231. Goto, Fill
  232. 2ButtonF:
  233. FileDelete, %A_Temp%\List.txt
  234. FilterLetterOrNumber=F
  235. Goto, Fill
  236. 2ButtonG:
  237. FileDelete, %A_Temp%\List.txt
  238. FilterLetterOrNumber=G
  239. Goto, Fill
  240. 2ButtonH:
  241. FileDelete, %A_Temp%\List.txt
  242. FilterLetterOrNumber=H
  243. Goto, Fill
  244. 2ButtonI:
  245. FileDelete, %A_Temp%\List.txt
  246. FilterLetterOrNumber=I
  247. Goto, Fill
  248. 2ButtonJ:
  249. FileDelete, %A_Temp%\List.txt
  250. FilterLetterOrNumber=J
  251. Goto, Fill
  252. 2ButtonK:
  253. FileDelete, %A_Temp%\List.txt
  254. FilterLetterOrNumber=K
  255. Goto, Fill
  256. 2ButtonL:
  257. FileDelete, %A_Temp%\List.txt
  258. FilterLetterOrNumber=L
  259. Goto, Fill
  260. 2ButtonM:
  261. FileDelete, %A_Temp%\List.txt
  262. FilterLetterOrNumber=M
  263. Goto, Fill
  264. 2ButtonN:
  265. FileDelete, %A_Temp%\List.txt
  266. FilterLetterOrNumber=N
  267. Goto, Fill
  268. 2ButtonO:
  269. FileDelete, %A_Temp%\List.txt
  270. FilterLetterOrNumber=O
  271. Goto, Fill
  272. 2ButtonP:
  273. FileDelete, %A_Temp%\List.txt
  274. FilterLetterOrNumber=P
  275. Goto, Fill
  276. 2ButtonQ:
  277. FileDelete, %A_Temp%\List.txt
  278. FilterLetterOrNumber=Q
  279. Goto, Fill
  280. 2ButtonR:
  281. FileDelete, %A_Temp%\List.txt
  282. FilterLetterOrNumber=R
  283. Goto, Fill
  284. 2ButtonS:
  285. FileDelete, %A_Temp%\List.txt
  286. FilterLetterOrNumber=S
  287. Goto, Fill
  288. 2ButtonT:
  289. FileDelete, %A_Temp%\List.txt
  290. FilterLetterOrNumber=T
  291. Goto, Fill
  292. 2ButtonU:
  293. FileDelete, %A_Temp%\List.txt
  294. FilterLetterOrNumber=U
  295. Goto, Fill
  296. 2ButtonV:
  297. FileDelete, %A_Temp%\List.txt
  298. FilterLetterOrNumber=V
  299. Goto, Fill
  300. 2ButtonW:
  301. FileDelete, %A_Temp%\List.txt
  302. FilterLetterOrNumber=W
  303. Goto, Fill
  304. 2ButtonX:
  305. FileDelete, %A_Temp%\List.txt
  306. FilterLetterOrNumber=X
  307. Goto, Fill
  308. 2ButtonY:
  309. FileDelete, %A_Temp%\List.txt
  310. FilterLetterOrNumber=Y
  311. Goto, Fill
  312. 2ButtonZ:
  313. FileDelete, %A_Temp%\List.txt
  314. FilterLetterOrNumber=Z
  315. Goto, Fill
  316.  
  317. }
  318.  
  319. Close:
  320. IfWinNotExist, Cargando
  321. {
  322. GuiControl, %GuiNum%:Hide, Button_Close1
  323. If GuiNum=2
  324. {
  325. 2GuiClose:
  326. If Looping=
  327. {
  328. FileDelete, %A_Temp%\PathsList.ini
  329. FileDelete, %A_Temp%\PhList.txt
  330. FileDelete, %A_Temp%\PathList.txt
  331.  
  332. MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
  333. }
  334. }
  335. }

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 » Logged
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« 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.
Logged

skwire
Global Moderator
*****
Posts: 4,114



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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:

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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.    MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  124. Guishow:
  125.    Gui, 2:Show,, Seleccione el Folder :
  126.    Loop, 26
  127.    {
  128.        GuiControl, Enable, % Chr( 64 + A_Index )
  129.    }
  130.  
  131.  
  132. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  133.    FileDelete, %A_Temp%\List.txt
  134.    If A_GuiEvent <> S
  135.        Return
  136.    lns=0
  137.    SoundPlay, 0
  138.    Sng:=
  139.    TV_GetText(SelectedItemText, A_EventInfo)
  140.    ItemText=%SelectedItemText%
  141.    ParentID := A_EventInfo
  142.    Loop  ; Build the full path to the selected folder.
  143.    {
  144.        If MainGuiLeft=0
  145.            Break
  146.        ParentID := TV_GetParent(ParentID)
  147.        If not ParentID  ; No more ancestors.
  148.            Break
  149.        TV_GetText(ParentText, ParentID)
  150.        SelectedItemText = %ParentText%\%SelectedItemText%
  151.    }
  152.    sel := TV_GetSelection()
  153.    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  154.  
  155. 2ButtonA:
  156. 2ButtonB:
  157. 2ButtonC:
  158. 2ButtonD:
  159. 2ButtonE:
  160. 2ButtonF:
  161. 2ButtonG:
  162. 2ButtonH:
  163. 2ButtonI:
  164. 2ButtonJ:
  165. 2ButtonK:
  166. 2ButtonL:
  167. 2ButtonM:
  168. 2ButtonN:
  169. 2ButtonO:
  170. 2ButtonP:
  171. 2ButtonQ:
  172. 2ButtonR:
  173. 2ButtonS:
  174. 2ButtonT:
  175. 2ButtonU:
  176. 2ButtonV:
  177. 2ButtonW:
  178. 2ButtonX:
  179. 2ButtonY:
  180. 2ButtonZ:
  181.    TV_Delete()
  182.    FileDelete, %A_Temp%\List.txt
  183.    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  184.    Goto, Fill
  185.  
  186. }
  187.  
  188. Close:
  189.    IfWinNotExist, Cargando
  190.    {
  191.        GuiControl, %GuiNum%:Hide, Button_Close1
  192.        If GuiNum=2
  193.        {
  194.        2GuiClose:
  195.            If Looping=
  196.            {
  197.                FileDelete, %A_Temp%\PathsList.ini
  198.                FileDelete, %A_Temp%\PhList.txt
  199.                FileDelete, %A_Temp%\PathList.txt
  200.  
  201.                SplashTextOff
  202.                Gui 2:Destroy
  203.                MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
  204.                ExitApp
  205.            }
  206.        }
  207. }
Logged

Edd
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« 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:

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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.    MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  124. Guishow:
  125.    Gui, 2:Show,, Seleccione el Folder :
  126.    Loop, 26
  127.    {
  128.        GuiControl, Enable, % Chr( 64 + A_Index )
  129.    }
  130.  
  131.  
  132. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  133.    FileDelete, %A_Temp%\List.txt
  134.    If A_GuiEvent <> S
  135.        Return
  136.    lns=0
  137.    SoundPlay, 0
  138.    Sng:=
  139.    TV_GetText(SelectedItemText, A_EventInfo)
  140.    ItemText=%SelectedItemText%
  141.    ParentID := A_EventInfo
  142.    Loop  ; Build the full path to the selected folder.
  143.    {
  144.        If MainGuiLeft=0
  145.            Break
  146.        ParentID := TV_GetParent(ParentID)
  147.        If not ParentID  ; No more ancestors.
  148.            Break
  149.        TV_GetText(ParentText, ParentID)
  150.        SelectedItemText = %ParentText%\%SelectedItemText%
  151.    }
  152.    sel := TV_GetSelection()
  153.    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  154.  
  155. 2ButtonA:
  156. 2ButtonB:
  157. 2ButtonC:
  158. 2ButtonD:
  159. 2ButtonE:
  160. 2ButtonF:
  161. 2ButtonG:
  162. 2ButtonH:
  163. 2ButtonI:
  164. 2ButtonJ:
  165. 2ButtonK:
  166. 2ButtonL:
  167. 2ButtonM:
  168. 2ButtonN:
  169. 2ButtonO:
  170. 2ButtonP:
  171. 2ButtonQ:
  172. 2ButtonR:
  173. 2ButtonS:
  174. 2ButtonT:
  175. 2ButtonU:
  176. 2ButtonV:
  177. 2ButtonW:
  178. 2ButtonX:
  179. 2ButtonY:
  180. 2ButtonZ:
  181.    TV_Delete()
  182.    FileDelete, %A_Temp%\List.txt
  183.    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  184.    Goto, Fill
  185.  
  186. }
  187.  
  188. Close:
  189.    IfWinNotExist, Cargando
  190.    {
  191.        GuiControl, %GuiNum%:Hide, Button_Close1
  192.        If GuiNum=2
  193.        {
  194.        2GuiClose:
  195.            If Looping=
  196.            {
  197.                FileDelete, %A_Temp%\PathsList.ini
  198.                FileDelete, %A_Temp%\PhList.txt
  199.                FileDelete, %A_Temp%\PathList.txt
  200.  
  201.                SplashTextOff
  202.                Gui 2:Destroy
  203.                MsgBox, 4096,Closing...,Don't worry I've alReady erased all temp files.,2.5
  204.                ExitApp
  205.            }
  206.        }
  207. }


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:

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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. {
  97.        If FirstLetterOrNumber=%FilterLetterOrNumber%
  98.        {
  99.            SplashTextOn, 200, 25, Cargando, Espere un momento..
  100.            FileAppend,
  101.            (
  102. %Letter%%TempFlderName%`n
  103.            ),%A_Temp%\PathList.txt,UTF-8
  104.        }
  105. }
  106.    }
  107.    IfExist, %A_Temp%\PathList.txt
  108.    {
  109.        MsgBox, 4096,,I created a txt document named "PathList.txt", this is the content...
  110.        SplashTextOff
  111.        RunWait, %A_Temp%\PathList.txt
  112.        SplashTextOn, 200, 25, Cargando, Espere un momento..
  113.    }
  114.    Else
  115.    {
  116.        SplashTextOff
  117.        MsgBox, 4096,,You don't have folders that begins with "%FilterLetterOrNumber%" on "%Letter%".
  118.        MsgBox, 4096,,Try with other letter...
  119.        Goto, Guishow
  120.    }
  121.    Loop
  122.    {
  123.        IfExist, %A_Temp%\PathList.txt
  124.        {
  125.            FileReadLine, TreeRoot, %A_Temp%\PathList.txt, %A_Index%
  126.            If ErrorLevel
  127.            {
  128.                FileDelete, %A_Temp%\PathList.txt
  129.                Break
  130.            }
  131.            AddSubFoldersToTree(TreeRoot)
  132.  
  133.            AddSubFoldersToTree(Folder, ParentItemID = 0)
  134.            {
  135.                ; This function adds to the TreeView all subfolders in the specified folder.
  136.                ; It also calls itself recursively to gather nested folders to any depth.
  137.                Loop %Folder%\*.*, 2  ; Retrieve all of Folder's sub-folders.
  138.                {
  139.                    If ( SubStr( A_LoopFileName, 1, 1 ) = SubStr( Folder, 4, 1 ) )
  140.                    {
  141.                        AddSubFoldersToTree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentItemID, "Icon4"))
  142.                    }
  143.                }
  144.                TV_Modify(0, "Sort")
  145.                If ParentItemID!=0
  146.                    IniWrite, %A_LoopFileFullPath%, %A_Temp%\PathsList.ini, PathsList, %ParentItemID%
  147.            }
  148.        }
  149.    }
  150. IfExist, %A_Temp%\PathsList.ini
  151. {
  152.    MsgBox, 4096,,I created an ini document named "PathsList.ini", this is the content...
  153.    RunWait, %A_Temp%\PathsList.ini
  154. }
  155.   MsgBox, 4096,,The founded root(s) doesn't contain folders to add...
  156. Guishow:
  157.    Gui, 2:Show,, Seleccione el Folder :
  158. GuiControl, Enable, #
  159.    Loop, 26
  160.    {
  161.        GuiControl, Enable, % Chr( 64 + A_Index )
  162.    }
  163.  
  164.  
  165. MyTreeLabel: ; This subroutine handles user actions (such as clicking).
  166.    FileDelete, %A_Temp%\List.txt
  167.    If A_GuiEvent <> S
  168.        Return
  169.    lns=0
  170.    SoundPlay, 0
  171.    Sng:=
  172.    TV_GetText(SelectedItemText, A_EventInfo)
  173.    ItemText=%SelectedItemText%
  174.    ParentID := A_EventInfo
  175.    Loop  ; Build the full path to the selected folder.
  176.    {
  177.        If MainGuiLeft=0
  178.            Break
  179.        ParentID := TV_GetParent(ParentID)
  180.        If not ParentID  ; No more ancestors.
  181.            Break
  182.        TV_GetText(ParentText, ParentID)
  183.        SelectedItemText = %ParentText%\%SelectedItemText%
  184.    }
  185.    sel := TV_GetSelection()
  186.    IniRead, SelectedFullPath, %A_Temp%\PathsList.ini, PathsList, %sel%
  187. 2Button#:
  188. 2ButtonA:
  189. 2ButtonB:
  190. 2ButtonC:
  191. 2ButtonD:
  192. 2ButtonE:
  193. 2ButtonF:
  194. 2ButtonG:
  195. 2ButtonH:
  196. 2ButtonI:
  197. 2ButtonJ:
  198. 2ButtonK:
  199. 2ButtonL:
  200. 2ButtonM:
  201. 2ButtonN:
  202. 2ButtonO:
  203. 2ButtonP:
  204. 2ButtonQ:
  205. 2ButtonR:
  206. 2ButtonS:
  207. 2ButtonT:
  208. 2ButtonU:
  209. 2ButtonV:
  210. 2ButtonW:
  211. 2ButtonX:
  212. 2ButtonY:
  213. 2ButtonZ:
  214.    TV_Delete()
  215.    FileDelete, %A_Temp%\List.txt
  216.    StringRight, FilterLetterOrNumber, A_ThisLabel, 1
  217.    Goto, Fill
  218.  
  219. }
  220.  
  221. Close:
  222.    IfWinNotExist, Cargando
  223.    {
  224.        GuiControl, %GuiNum%:Hide, Button_Close1
  225.        If GuiNum=2
  226.        {
  227.        2GuiClose:
  228.            If Looping=
  229.            {
  230.                FileDelete, %A_Temp%\PathsList.ini
  231.                FileDelete, %A_Temp%\PhList.txt
  232.                FileDelete, %A_Temp%\PathList.txt
  233.  
  234.        ;Erasing virual drive
  235. {
  236. FileSetAttrib, -H, C:\%VLetter%
  237. RunWait, %ComSpec% /c subst %VLetter%: /D,,hide
  238. FileRemoveDir, C:\%VLetter%, 1
  239. }
  240.  
  241.                SplashTextOff
  242.                Gui 2:Destroy
  243.                MsgBox, 4096,Closing...,Don't worry I've already erased all temp files.,2.5
  244.                ExitApp
  245.            }
  246.        }
  247. }

« Last Edit: January 01, 2012, 06:09:25 PM by Edd » Logged
kunkel321
Supporting Member
**
Posts: 392


see users location on a map View Profile Give some DonationCredits to this forum member
« 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.
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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 Wink
Logged

Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.443s | Server load: 0.07 ]