2008年2月13日

TreeTest.ahk

まあ一応



;TreeTest.ahk
;2008/02/13作成
;TreeView対応簡易Explorer
;基本的にPaper Plane xUIと同じ?ファイルの容量計算をしてみた

;仕様
;・このスクリプトのesExtPathにesExt5.exeのパスを書いておく
;・TreeViewクリックしたらサブフォルダのツリー作成+フォルダの内容表示

;問題点
;・多分大丈夫

;todo
;・esExt5.ahkと対応させる
; (対応させようとして関数化してみたら:=でエラーが出た)
;・機能の追加

;esExt5のパス
esExtPath = C:\Program Files\tool\.S\esExt\esExt5.exe

;TreeView1作成
Gui, Add, TreeView, w150 h400 gTreeView1
Gui, Add, ListView, x+5 h400 gListView1, Name|Ext|Size|Date
Gui, Show

;ドライブの一覧取得
DriveGet, ListDrive, List
;無限ループ
Loop
{
;まだドライブがある時
StringLen, Len, ListDrive
if Len <> 0
{
;1文字目取得
StringLeft, DriveName, ListDrive, 1
;名前作成
DriveName = %DriveName%:
;ツリービュー追加
TV_Add(DriveName)
;次のドライブへ
StringTrimLeft, ListDrive, ListDrive, 1
;Msgbox, %Len%, %ListDrive%, %DriveName%
}
;もう無い時
else
{
;無限ループ脱出
break
}
}
return

GuiClose:
ExitApp

;TreeViewがクリックされたら
TreeView1:
;ListViewの内容消去
LV_Delete()
;ListViewの内容作成
GetChild(TV_GetSelection())
return

;フォルダツリー+フォルダ一覧作成
;引数はTreeViewのID
GetChild(ID)
{
if A_GuiEvent = S
{
GetPath := CreatePath(ID)
;Msgbox, GetChild:%GetPath%
;属性取得
FileGetAttrib, Attrib, %GetPath%
;Msgbox, %Attrib%
;ディレクトリだったら
if Attrib contains D
{
Loop, %GetPath%\*.*
{
;サイズ取得
if A_LoopFileSize <= 999999
{
size = %A_LoopFileSize%
}
else if A_LoopFileSizeKB >= 1000
{
if A_LoopFileSizeMB >= 1000
{
size = %A_LoopFileSizeMB%M
}
else
{
size = %A_LoopFileSizeKB%K
}
}
;日付変換
FormatTime, Date, %A_LoopFileTimeModified%, yyyy-MM-dd
;リストに追加
LV_Add("", A_LoopFileName, A_LoopFileExt, size, Date)
}
;子がなかった場合=まだ選択されていなかった場合
if TV_GetChild(ID) = 0
{
Loop, %GetPath%\*.*, 2
{
;ツリーに追加
TV_Add(A_LoopFileName, ID)
}
}
}
}
;幅調整
LV_ModifyCol(1)
LV_ModifyCol(2)
LV_ModifyCol(3)
Gui, Show, , %GetPath%
}

;フルパス作成
;引数はTreeViewのID
CreatePath(ID)
{
global TestPath
;テキスト取得
TV_GetText(CurName, ID)
;ドライブだったら
if CurName contains :
{
;パス作成
TestPath = %CurName%
}
else
{
;上のフォルダに行く
CreatePath(TV_GetParent(ID))
;パス作成
TestPath = %TestPath%\%CurName%
;Msgbox, %TestPath%
}
;Msgbox, CreatePath:%ID%, %CurName%, %TestPath%
return %TestPath%
}

ListView1:
;ダブルクリックだったら
if A_GuiEvent = DoubleClick
{
;名前取得
LV_GetText(testName, A_EventInfo)
;パス取得
GetPath := CreatePath(TV_GetSelection())
;Msgbox, %GetPath%\%testName%
Pathtest = %GetPath%\%testName%
Run, %esExtPath% %Pathtest%
}
return
preとcode使ってもプレビューではタブ表記になるけど駄目みたいだ・・・