I have a text file with contents like so:
01 Dir1
abcd
efg
hij
klm
nop
qrs
tuv
wxy
zab
yxw
vut
dcb
02 Dir2
abcd
efg
hij
klm
nop
qrs
tuv
wxy
zab
yxw
vut
dcb
I get an array which is created by reading the file:
string[] lines = File.ReadAllLines(path);
This gives me an array will all the entries including the empty one.
The idea behind the text file is that there is a folder and the files in that folder following it. So, "01 Dir1" is a folder and every line after that till an empty line is a file.
What I am trying is to have a list of arrays, so from the above sample there will be two arrays in the list, one starting from "01 Dir1" till the empty entry and the next from "02 Dir2" till the end.
I can loop through the initial array and create list for each individual directory but is there another way to do it?
The problem with that approach is that it will end up having the same data in different sets in memory, one from the ReadAllLines array and other the subs from it.
The problem with that approach is that it will end up having the same data in different sets in memory, one from the ReadAllLines array and other the subs from it.... why is this a problem? The garbage collector will take take of the objects you don't need anymore when the object goes out of scope.ReadAllLinesin a single array then don't use it. There are other ways to read text files that you can customize how the file is read.