I think I'm very close to having a working solution, however I'm having difficulty with parent/child directory recursing.
The example posted below works, as long as each directory has only one level of separation from the previous value, but if the path value contains directory levels that weren't previously added, only the last folder is displayed (see "C:\Fil9\Fil8\Fil7\SZZZ1\OneMore\NewFile.azz").
I think I need help with being able to make a folder a child too, instead of always a parent, to list all the directory levels. Not really sure though... I'm actually stuck.
Hopefully I've clearly described the issue. Thanks in advance!
Note: The "visual" of the file tree still needs some work, such as the root, which I will fix after figuring out this issue.
Code: Select all
#SingleInstance, Force
Gui, Font, s10, Consolas
Gui, Margin, 10, 10
Gui, Add, Edit, w340 r18 vEDT
Gui, Show, AutoSize, Example
Paths =
(
C:\abc.d
C:\mbc.d
C:\Fil1\Dele.e
C:\Fil1\Delema.d
C:\Fil1\File2\Deledmad.d
C:\Fil1\File2\Alada.d
C:\Fil3\mada.d
C:\Fil3\madaf.d
C:\Fil9\Fil8\Fil7\SZZZ1\OneMore\NewFile.azz
C:\dbc.d
)
Paths := StrSplit(Paths, "`n")
Parent := {}
Child := {}
For Index, Value In Paths {
SplitPath, Value, Name, Dir, Ext, NameNoExt, Drv
Dir := Dir "\"
RegExMatch(Value, "(.+\\\K|^)[^\\]+(?=\\)", Folder)
StrReplace(Dir, "\",, Level)
Parent[Dir] := {"Parent": Dir, "Level": Level, "Folder": Folder}
Child[Value] := {"Parent": Dir, "Child": Name}
}
CurrParent := ""
PrevParent := ""
Output := ""
For Index1, Value1 In Parent {
For Index2, Value2 In Child {
If (Value1.Parent = Value2.Parent) {
CurrParent := Value2.Parent
If (CurrParent <> PrevParent) {
PrefixA := Format("{:" Value1.Level * 4 "}", "|-- ")
Output .= PrefixA . Value1.Folder "`n"
}
Prefix := Format("{:" Value1.Level * 4 "}", "|-- ")
Output .= Prefix . Value2.Child "`n"
PrevParent := Value2.Parent
}
}
}
GuiControl,, EDT, % Output
This is what I get:
Code: Select all
C:
|-- abc.d
|-- dbc.d
|-- mbc.d
|-- Fil1
|-- Dele.e
|-- Delema.d
|-- File2
|-- Alada.d
|-- Deledmad.d
|-- Fil3
|-- mada.d
|-- madaf.d
|-- OneMore
|-- NewFile.azz
This is what I want:
Code: Select all
C:
|-- abc.d
|-- dbc.d
|-- mbc.d
|-- Fil1
|-- Dele.e
|-- Delema.d
|-- File2
|-- Alada.d
|-- Deledmad.d
|-- Fil3
|-- mada.d
|-- madaf.d
|-- Fil9
|-- Fil8
|-- Fil7
|-- SZZZ1
|-- OneMore
|-- NewFile.azz