ioa747 Posted December 13, 2023 Posted December 13, 2023 (edited) Structure of a folder in text, with tree format for a more visually improved format TreeStructureDir.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/211237-treestructuredir ;---------------------------------------------------------------------------------------- ; Title...........: TreeStructureDir.au3 ; Description.....: Structure of a folder in text, with tree format for a more visually improved format ; AutoIt Version..: 3.3.16.1 Author: ioa747 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> Global $sPath = "C:\Program Files (x86)\AutoIt3" Global $sTxt = TreeStructureDir($sPath) ConsoleWrite($sPath & @CRLF & $sTxt & @CRLF) ;---------------------------------------------------------------------------------------- Func TreeStructureDir($sDirectoryPath) Local $aFolders, $iColCnt, $aSplit, $Result $aFolders = _FileListToArrayRec($sDirectoryPath, "*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT) If @error Then Return SetError(@error, @extended, "") $iColCnt = 0 _ArrayColInsert($aFolders, 1) For $i = 1 To $aFolders[0][0] $aSplit = StringSplit($aFolders[$i][0], "\") If $aSplit[0] > $iColCnt Then $iColCnt = $aSplit[0] Next For $i = 1 To $iColCnt - 1 _ArrayColInsert($aFolders, 1) Next For $i = 1 To $aFolders[0][0] $aSplit = StringSplit($aFolders[$i][0], "\") For $x = 1 To $aSplit[0] $aFolders[$i][$x] = $aSplit[$x] Next Next $iColCnt = UBound($aFolders, 2) - 1 For $i = 1 To $aFolders[0][0] For $x = $iColCnt To 1 Step -1 If StringLen($aFolders[$i][$x]) > 0 Then If $aFolders[$i][$x] = $aFolders[0][$x] Then $aFolders[$i][$x] = "│ " Else $aFolders[0][$x] = $aFolders[$i][$x] If $x > 1 Then If $i < $aFolders[0][0] Then If $aFolders[$i][$x - 1] = $aFolders[$i + 1][$x - 1] Then $aFolders[$i][$x] = "├─ " & $aFolders[0][$x] Else $aFolders[$i][$x] = "└─ " & $aFolders[0][$x] EndIf Else $aFolders[$i][$x] = "└─ " & $aFolders[0][$x] EndIf Else $aFolders[$i][$x] = "├─ " & $aFolders[0][$x] EndIf EndIf Else $aFolders[0][$x] = "" EndIf Next Next For $i = $aFolders[0][0] To 1 Step -1 For $x = 1 To $iColCnt If $x = 1 And StringLen($aFolders[0][$x]) > 0 Then If $aFolders[$i][$x] = "│ " Then $aFolders[$i][$x] = " " If StringLeft($aFolders[$i][$x], 3) = "├─ " Then $aFolders[$i][$x] = StringReplace($aFolders[$i][$x], "├─ ", "└─ ") $aFolders[0][$x] = "" EndIf EndIf If StringLen($aFolders[$i][$x]) = 0 Then $aFolders[0][$x] = ":FIX:" If $aFolders[0][$x] = ":FIX:" Then If $aFolders[$i][$x] = "│ " Then $aFolders[$i][$x] = " " ElseIf $aFolders[$i][$x] = "" Then ;nothing Else $aFolders[0][$x] = "" EndIf If StringLeft($aFolders[$i][$x], 3) = "├─ " Then $aFolders[$i][$x] = StringReplace($aFolders[$i][$x], "├─ ", "└─ ") $aFolders[0][$x] = "" EndIf EndIf Next Next For $i = 1 To $aFolders[0][0] For $x = 1 To $iColCnt $Result &= $aFolders[$i][$x] Next $Result &= @CRLF Next ;~ _ArrayDisplay($aFolders) Return BinaryToString(StringToBinary($Result, 4), 4) EndFunc ;==>TreeStructureDir ;---------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Edited December 13, 2023 by ioa747 Gianni and Musashi 2 I know that I know nothing
argumentum Posted December 13, 2023 Posted December 13, 2023 (edited) Love it !. Thanks for sharing Edited December 13, 2023 by argumentum =) ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted December 13, 2023 Author Posted December 13, 2023 thank you very much, I already adopted it argumentum 1 I know that I know nothing
Gianni Posted December 13, 2023 Posted December 13, 2023 just for fun, here's an alternative 'shortened' version ; https://www.autoitscript.com/forum/topic/211237-treestructuredir ;---------------------------------------------------------------------------------------- ; Title...........: TreeStructureDir.au3 ; Description.....: Structure of a folder in text, with tree format for a more visually improved format ; AutoIt Version..: 3.3.16.1 Author: ioa747 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 Global $sPath = "C:\Program Files (x86)\AutoIt3" Global $sTxt = TreeStructureDir($sPath) ConsoleWrite($sPath & @CRLF & $sTxt & @CRLF) ;---------------------------------------------------------------------------------------- Func TreeStructureDir($sDirectoryPath) Local $sTree = '', $iPID = Run(@ComSpec & ' /c tree "' & $sDirectoryPath & '" /A', '', @SW_HIDE, 8) While ProcessExists($iPID) $sTree &= StdoutRead($iPID) WEnd Return $sTree EndFunc ;==>TreeStructureDir ;---------------------------------------------------------------------------------------- argumentum and ioa747 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
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