I wrote this because I really dislike the way that FileSelectFolder works when giving it a starting directory. Let me know what you think.
Code: Select all
#SingleInstance,Force
d1:=new dir({win:1,w:200,h:200,start:A_ScriptDir}) ;Create a treeview in window 1 with a width and height of 200 starting in A_ScriptDir
d2:=new dir({win:1,w:200,x:"+10",h:200,start:A_Desktop}) ;Same as above but using x+10 and starting in A_Desktop
d3:=new dir({win:2,w:200,h:200,start:A_WinDir}) ;Same as above but on window 2 and starting in A_WinDir
for a,b in [[1,"xm vfirst"],[1,"x+155 vsecond"],[2,"xm vthird"]] ;setting up the buttons to display the current directories
Gui,% b.1 ":Add",Button,% "ggo " b.2,Directory
for a,b in [[1,"xm vd1"],[1,"x+160 vd2"],[2,"xm vd3"]] ;setting up the buttons to refresh the current directories
Gui,% b.1 ":Add",Button,% "grefresh " b.2,Refresh
Gui,1:Show,% "x" (A_ScreenWidth/2)-300,Directory 1
Gui,2:Show,% "x" (A_ScreenWidth/2)+150,Directory 2
return
GuiClose:
2GuiClose:
ExitApp
return
go:
result:={first:d1.last,second:d2.last,third:d3.last} ;creates an object with all of the directories
MsgBox,% result[A_GuiControl] ;display the directory
return
refresh:
%A_GuiControl%["refresh"]() ;would normally be done d1.refresh() but I wanted to make the code smaller
return
class dir{
static con:=[]
__New(info){
static
win:=info.win?info.win:1,start:=info.start,pos:=""
for a,b in ["x","y","w","h"]
if info[b]
pos.=b info[b] " "
Gui,%win%:Add,TreeView,%pos% gtree AltSubmit hwndhwnd
GuiControl,%win%:+v%hwnd%,%hwnd%
Gui,%win%:Default
this.win:=info.win?info.win:1,dir.con[hwnd]:=this,this.hwnd:=hwnd
this.refresh(),this.start(start)
}
refresh(){
start:=this.getdir(),this.tv(),TV_Delete(),dirs:=[]
DriveGet,List,List
Loop,Parse,list
dirs[A_LoopField ":"]:=0
this.populate(dirs),this.start(start)
}
start(start){
ll:=strsplit(start,"\")
for a,b in ll{
index:=A_Index
while,ss:=TV_GetNext(ss,"F"),TV_GetText(dd,ss),TV_GetText(text,TV_GetChild(ss))
if (dd=b){
if (text=""&&TV_GetChild(ss))
TV_Delete(TV_GetChild(ss)),this.populate({this.getdir(ss):ss})
TV_Modify(ss,"Expand VisFirst Focus Select")
if ll.MaxIndex()=index
break
}
}
}
populate(info){
this.tv()
GuiControl,-Redraw,% this.hwnd
for a,b in info{
if !(b)
root:=TV_Add(a),this.addsub({dir:a,tv:root})
else
Loop,%a%\*.*,2
{
if A_Index=100
SplashTextOn,,50,Please Wait,There are quite a few directories here
root:=TV_Add(A_LoopFileName,b),this.addsub({dir:A_LoopFileFullPath,tv:root})
}
}
GuiControl,+Redraw,% this.hwnd
SplashTextOff
}
addsub(info){
Loop,% info.dir "\*.*",2
return this.tv(),TV_Add("",info.tv)
}
tree(){
tree:
tt:=dir.con[A_GuiControl],TV_GetText(text,TV_GetChild(A_EventInfo))
if (A_GuiControlEvent="+"&&text="")
TV_Delete(TV_GetChild(A_EventInfo)),tt.populate({tt.getdir(A_EventInfo):A_EventInfo}),TV_Modify(A_EventInfo,"VisFirst")
tt.last:=tt.getdir(A_EventInfo)
return
}
getdir(tv=""){
this.tv(),tv:=tv?tv:TV_GetSelection(),TV_GetText(dd,tv)
while,tv:=TV_GetParent(tv),TV_GetText(text,(tv))
dd:=text "\" dd
return dd
}
tv(){
Gui,% this.win ":TreeView",% this.hwnd
}
}