(已解决)如何实现treeview递归?
本帖最后由 jinyue115 于 2011-7-29 14:52 编辑#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 568);,$iStyle, $WS_EX_CLIENTEDGE)
_GUICtrlTreeView_BeginUpdate($hTreeView)
;==========================================================================
TreeViewList()
;==========================================================================
_GUICtrlTreeView_EndUpdate($hTreeView)
GUISetState()
Do
Until GUIGetMsg()=-3
Func TreeViewList()
$filelist = _FileListToArray(@ProgramFilesDir)
If @error =1 then Exit
If UBound ($filelist) <> '' Then
For $i = 1 To $filelist
$hitem=_GUICtrlTreeView_Add($hTreeView,0,$filelist[$i])
If StringInStr(Filegetattrib(@ProgramFilesDir & '\' & $filelist[$i]),'D') Then
$filelistb = _FileListToArray(@ProgramFilesDir & '\' & $filelist[$i])
If UBound ($filelistb) <> '' Then
For $j = 1 To $filelistb
If StringInStr(FileGetAttrib(@ProgramFilesDir & '\' & $filelist[$i] & '\' & $filelistb[$j] ),'D') Then
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView,$hitem,$filelistb[$j])
$hchildchilditem = _GUICtrlTreeView_AddChild($hTreeView,$hChildItem,$filelistb[$j])
$filelistc = _FileListToArray(@ProgramFilesDir & '\' & $filelist[$i] & '\' & $filelistb[$j])
If UBound ($filelistc) <> '' Then
For $k =1 To $filelistc
_GUICtrlTreeView_AddChild($hTreeView ,$hchildchilditem,$filelistc[$k])
Next
EndIf
;~ TreeViewList()
Else
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView,$hitem,$filelistb[$j])
EndIf
Next
EndIf
EndIf
Next
EndIf
EndFunc
为什么不能回复了? 为什么这样不行?#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 568);,$iStyle, $WS_EX_CLIENTEDGE)
_GUICtrlTreeView_BeginUpdate($hTreeView)
;==========================================================================
TreeViewList(@ProgramFilesDir)
;==========================================================================
_GUICtrlTreeView_EndUpdate($hTreeView)
GUISetState()
Do
Until GUIGetMsg()=-3
Func TreeViewList($path)
Local $filepath
$filelist = _FileListToArray($path)
If @error =1 then Exit
If UBound ($filelist) <> '' Then
For $i = 1 To $filelist
$hitem=_GUICtrlTreeView_Add($hTreeView,0,$filelist[$i])
$filepath =$path & '\' & $filelist[$i]
If StringInStr(Filegetattrib(@ProgramFilesDir & '\' & $filelist[$i]),'D') Then
$filelistb = _FileListToArray(@ProgramFilesDir & '\' & $filelist[$i])
If UBound ($filelistb) <> '' Then
For $j = 1 To $filelistb
$filepath =$path & '\' & $filelist[$i] & '\' & $filelistb[$j]
If StringInStr(FileGetAttrib(@ProgramFilesDir & '\' & $filelist[$i] & '\' & $filelistb[$j] ),'D') Then
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView,$hitem,$filelistb[$j])
;~ $hchildchilditem = _GUICtrlTreeView_AddChild($hTreeView,$hChildItem,$filelistb[$j])
;~ $filelistc = _FileListToArray(@ProgramFilesDir & '\' & $filelist[$i] & '\' & $filelistb[$j])
;~ If UBound ($filelistc) <> '' Then
;~ For $k =1 To $filelistc
;~ _GUICtrlTreeView_AddChild($hTreeView ,$hchildchilditem,$filelistc[$k])
;~ Next
;~ EndIf
TreeViewList($filepath)
Else
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView,$hitem,$filelistb[$j]);list all the non folder files
EndIf
Next
EndIf
EndIf
Next
EndIf
Return
EndFunc 回复 2# jinyue115
http://www.autoitx.com/thread-19307-19-1.html这里看看,afan有个递归搜索的代码。。。。 回复 3# 131738
谢谢
不过 他的那个和我这个不是同一类的
我现在树形遍历整个文件夹可以大概知道怎么做
但是我不知道那个遍历文件夹的递归函数到底怎么写 #include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 568);,$iStyle, $WS_EX_CLIENTEDGE)
_GUICtrlTreeView_BeginUpdate($hTreeView)
;==========================================================================
TreeViewList(@ProgramFilesDir, 1)
;==========================================================================
_GUICtrlTreeView_EndUpdate($hTreeView)
GUISetState()
Do
Until GUIGetMsg() = -3
Func TreeViewList($path, $item)
Local $filepath, $hitem
$filelist = _FileListToArray($path)
If @error = 1 then Exit
If UBound($filelist) <> '' Then
For $i = 1 To $filelist
$hitem = _GUICtrlTreeView_Add($hTreeView, 0, $filelist[$i])
If $item <> '' Then $item = $hitem
$filepath = $path & '\' & $filelist[$i]
If StringInStr(FileGetAttrib($filepath), 'D') Then
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView, $item, $filelist[$i])
If $item <> '' Then $item = $hitem
;~ TreeViewList($filepath,$item)
Else
$hChildItem = _GUICtrlTreeView_AddChild($hTreeView, $hitem, $filelist[$i]);list all the non folder files
EndIf
Next
EndIf
Return
EndFunc ;==>TreeViewList Func Recursion($current,$flag)
If $flag = '' Then $item1 = _GUICtrlTreeView_Add($hTreeView,0,$current,$hImage,$hImage)
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
If $flag <> '' Then $item1 = $flag
$item2 = _GUICtrlTreeView_AddChild($hTreeView,$item1,$file);,$hImage,$hImage)
Recursion($current & "\" & $file,$item2)
Else
If $flag <> '' Then $item1 = $flag
$item3 = _GUICtrlTreeView_AddChild($hTreeView,$item1,$file,$hImage,$hImage)
EndIf
WEnd
Return 进来学习下 !~~ 呵呵带走了 呵呵呵。。。。
页:
[1]