I have been working on this problem for about a week now..and I just can't figure out how to accomplish this.

I have a text file that is located in several different locations on a server, that has varied information.

An example of this of this file looks like:

[Natural Selection]

[Natural Selection/Marines]

[Server Regulars]

[Natural Selection/Marines/Test Channel]

[Server Regulars/Me/You/Everyone]

[Natural Selection/Aliens]

The text between the '/'s represents a separate sub-channels to the parent channels that a 3rd party app uses. There can be an infinite amount of channels and subchannels, so the script will need to accommodate all of that.

What I need to do is organize each channel with its sub channel.

So the formatting of the channels above would like like this:

Code:
Natural Selection
     Marines
          Test Channel
     Aliens
Server Regulars
     Me
          You
               Everyone
Now I can get a list of the channels by using simple spliting on [ and ], but I am haing issues matching the sub-channels up with their parent channels like above. The channels do not appear in any particular order in the file.

Also, I cannot simply re-order the the channels because I need to have the ability to store the position that the channel s appear in the text file, so I can edit or delete them through code.

Got any ideas?, my brain is fried from working on this.