'How to sort file path names in hierarchy basis?
I want to sort out file names in hierarchy basis.
Let say I have below list of folders:
D:Movies\Hollywood\Comedy\adultcomedy
D:Movies\Hollywood\Comedy\horrorcomedy
D:Movies\Hollywood\Romantic\ adult
D:Movies\Bollywood\Action\comedy
D:Movies\Bollywood
D:Movies\Hollywood\Comedy
D:Movies\Hollywood
D:Movies
D:Movies\Hollywood\Romantic
I want to sort them in single line, which means the last children should be sorted first, and grand grand parent should be sorted as last Child
(I.e):
- Movies — Grand parent
- Hollywood — child of Movies
- Bollywood — child of movies / Sibiling of Hollywood
- Comedy — child of hollywood / grand child of Movies
- adultcomedy— child of Comedy / descendant for Movies
- horrorcomedy — child of Comedy /sibiling of adultcomedy
- Romantic — child of Hollywood / Sibiling of Comedy and same for others
Here by I wanted to sort this as descendant from grand parent.
(i.e) —> 4 th level is extreme grand child in this structure, which means it should sort:
- As first element
adultcomedy
- then it’s sibiling
horrorcomedy
- then 4th Level of grand children
adult
fromRomantic
- then
comedy
fromAction
- then
Comedy
which is child of Hollywood and parent ofadultcomedy,horrorcomedy
and - then
Romantic
- then
Hollywood
- then
Bollywood
- finally
Movies
.
D:Movies\Hollywood\Comedy\adultcomedy D:Movies\Hollywood\Comedy\horrorcomedy D:Movies\Hollywood\Romantic\ adult
D:Movies\Bollywood\Action\comedy D:Movies\Hollywood\Comedy D:Movies\Hollywood\Romantic D:Movies\Hollywood D:Movies\Bollywood
D:Movies
Here I can’t use array,. Only I can use tree strucutre to solve this problem.,
What I have tried.,
- tried to count length but it’s failed due to dynamic path change
- checked whether another path has substring of another path
But none of the algorithms are working.
Sample code to understand the structure:
<forall _="ChildrenWithKey" name="fDir" in="vtList" param="ElementDir" >
<!-- here vtList has element paths as children & all the path has a Key:ElementDir name- alias name, so that we can use this tree anywhere -->
<!-- lets consider the list of paths above mentioned all has a Key:ElementDir -->
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|