本帖最后由 lfx99 于 2012-2-2 14:38 编辑
用一个包含具体路径的txt文件,在TreeView上显示,但路径多为重复,想了用 _GUICtrlTreeView_FindItemEx搜索以避免重复,但我只能做到第一层。苦思了好几天,无果,求助高手指点。。
附上代码 和 txt文件。#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
#include <GuiTreeView.au3>
Global $File = @ScriptDir & "\pach.txt"
$GUI = GUICreate("test", 350, 500, -1, -1)
$TreeGui = _GUICtrlTreeView_Create($GUI, 15, 15, 280, 430, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUISetState(@SW_SHOW)
_AddToList($TreeGui, $File)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _AddToList($TreeView, $LiseFile)
Local $item[10000], $StrAd, $StrAd1
_GUICtrlTreeView_BeginUpdate($TreeView)
$line = _FileCountLines($LiseFile)
For $i = 1 To $line
$str = FileReadLine($LiseFile, $i)
If StringRight($str, 1) = '\' Then $str = StringTrimRight($str, 1)
$strArray = StringSplit($str, '\')
If Not @error Then
For $o = 1 To $strArray[0]
$StrAd &= "" & $strArray[$o]
$StrAdNew = StringTrimLeft($StrAd, 1)
$hdle = _GUICtrlTreeView_FindItemEx($TreeView, $StrAdNew)
If $hdle Then
Else;如没有则逐渐建立。(如第一项)
$item[$o] = _GUICtrlTreeView_AddChild($TreeView, $item[$o - 1], $strArray[$o])
EndIf
Next
$StrAd = ''
EndIf
Next
_GUICtrlTreeView_EndUpdate($TreeView)
EndFunc ;==>_AddToList
txt文件:Temp\Temp1\add\AU3\文件夹\文件夹2
Temp\Temp1\add\AU3\文件夹\文件夹2
Temp\Temp1\add\AU3\文件夹2\文件夹3
Temp0\add\AU3
Temp0\add\AU3\myfile.inf
Temp0\add\AU3\AU3\myfile
|