AZJIO Posted September 30, 2012 Share Posted September 30, 2012 listC:folder1folder2folder3file1 C:folder1folder2folder3Readme.txt C:folder1folder2folder4file4 C:folder1folder2folder4Readme.txt C:folder1folder2folder5file2 C:folder1folder2folder5file5 C:folder1folder2file6 C:folder1folder2file7expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) ; $ListFile = @ScriptDir & 'ListFile.txt' $ListFile = FileOpenDialog('Open', @ScriptDir, 'All (*.*)', 3) If @error Then Exit Global $sTVParent, $aLastPath[125][3] = [[0]] ; En $LngTitle = 'View a list of files' $sTVParent = 'List' $Lng1 = 'item,' $Lng2 = 'sec' ; Ru If @OSLang = 04419 Then $LngTitle = 'Просмотр списка файлов' $sTVParent = 'Список' $Lng1 = 'пунктов, за' $Lng2 = 'сек' EndIf $hGui = GUICreate($LngTitle, 540, 560, -1, -1, $WS_OVERLAPPEDWINDOW) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $TreeView = GUICtrlCreateTreeView(0, 0, 540, 560, -1, $WS_EX_CLIENTEDGE) GUICtrlSetResizing(-1, 2 + 4 + 32 + 64) $hTreeView = GUICtrlGetHandle($TreeView) $hImage = _GUIImageList_Create(16, 16, 5, 1) _GUIImageList_AddIcon($hImage, @SystemDir & 'shell32.dll', -4) _GUIImageList_AddIcon($hImage, @SystemDir & 'shell32.dll', -5) _GUIImageList_AddIcon($hImage, @SystemDir & 'shell32.dll', 0) _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage) $E = '' $i = 1 While 1 $i += 1 $sExt = RegEnumKey("HKCR", $i) If @error Or StringLeft($sExt, 1) <> '.' Then ExitLoop $ico1 = _FileDefaultIcon($sExt) If Not @error Then Switch UBound($ico1) Case 2 If StringInStr(';.exe;.scr;.ico;.ani;.cur;', ';' & $sExt & ';') Then ContinueLoop Else _GUIImageList_AddIcon($hImage, $ico1[1], 0) If @error Then ContinueLoop EndIf Case 3 _GUIImageList_AddIcon($hImage, $ico1[1], $ico1[2]) If @error Then ContinueLoop EndSwitch $E &= '|' & $sExt EndIf WEnd $E = StringTrimLeft($E, 1) $aE = StringSplit($E, '|') $aLastPath[0][1] = _GUICtrlTreeView_Add($hTreeView, 0, $sTVParent, 0, 0) $aList = StringSplit(StringReplace(FileRead($ListFile), ':', ''), @CRLF, 1) _ArraySort($aList, 0, 1) $sep = Opt("GUIDataSeparatorChar", "") $timer = TimerInit() ; _GUICtrlTreeView_BeginUpdate($hTreeView) For $i = 1 To $aList[0] _AddFile($aList[$i]) Next ; _GUICtrlTreeView_EndUpdate($hTreeView) WinSetTitle($hGui, '', $LngTitle & ' (' & $aList[0] & ' ' & $Lng1 & ' ' & Round(TimerDiff($timer) / 1000, 2) & ' ' & $Lng2 & ')') Opt("GUIDataSeparatorChar", $sep) ControlTreeView($hGUI, '', $hTreeView, 'Expand', $sTVParent) GUISetState() While 1 Sleep(100000) WEnd Func _Exit() Exit EndFunc Func _AddFile($sPath) Local $hItem, $i, $ind = 0, $j, $tmp, $tmp1 $tmp = StringSplit($sPath, '') For $i = 1 To $tmp[0] If $tmp[$i] <> $aLastPath[$i][0] Then For $j = $i To $tmp[0] $aLastPath[$j][0] = $tmp[$j] $aLastPath[$j + 1][2] = 0 Next ExitLoop EndIf Next For $i = $i To $tmp[0] If $i = $tmp[0] Then $tmp1 = StringRegExpReplace($tmp[$i], '.*(.S+)', '1') $ind = _ArraySearch($aE, $tmp1) + 2 If @error Then $ind = 2 $aLastPath[$i][1] = _GUICtrlTreeView_AddChild($hTreeView, $aLastPath[$i - 1][1], $tmp[$i], $ind, $ind) Else If $aLastPath[$i][2] Then $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $aLastPath[$i - 1][1], $aLastPath[$i][2] - 1) $aLastPath[$i][1] = _GUICtrlTreeView_InsertItem($hTreeView, $tmp[$i], $aLastPath[$i - 1][1], $hItem, $ind, $ind) Else $aLastPath[$i][1] = _GUICtrlTreeView_AddChildFirst($hTreeView, $aLastPath[$i - 1][1], $tmp[$i], $ind, $ind) EndIf $aLastPath[$i][2] += 1 EndIf Next EndFunc Func _FileDefaultIcon($sExt) If $sExt = '' Or StringInStr($sExt, ':') Then Return SetError(1) Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", 0x00000040, _ ;$ASSOCF_VERIFY "dword", 15, _ ;$ASSOCSTR_DEFAULTICON "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, "") If Not $aCall[0] Then $sExt = StringReplace($aCall[5], '"', '') $sExt = StringSplit($sExt, ',') Opt('ExpandEnvStrings', 1) $sExt[1] = $sExt[1] Opt('ExpandEnvStrings', 0) Return SetError(0, 0, $sExt) ElseIf $aCall[0] = 0x80070002 Then Return SetError(1, 0, "{unknown}") ElseIf $aCall[0] = 0x80004005 Then Return SetError(1, 0, "{fail}") Else Return SetError(2, $aCall[0], "") EndIf EndFuncThe script is running slowly, if too many files. I want to load the file tree dynamically when you open a folder, rather than all at once.Is there a ready-made format and method of parsing? I do not want to reinvent the wheel.That's what I started trying ...root<1>C<2>folder1<3>folder2<4>folder3<5>file1<5>Readme.txt<4>folder4<5>file4<5>Readme.txt<4>folder5<5>file5<4>file6Step 1 "<3>folder2(<.+?)<3>"Step 2 "<4>(.+*)<" My other projects or all Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now