Something wrong with my logic and code!
Please help!!
I have the following text file, and I want to extract the first field (directory paths) of each line, and maybe write it to another file or an arraylist.
This is the file:
c:\mfta\t;c:\mfta\g|hr-admin|c:\mfta\s;c:\mfta\v|txt;doc;xls|n|n|y|y
c:\mfta\a;c:\mfta\e|hr-finance|c:\mfta\f;c:\mfta\g|txt;doc;xls|y|y|y|y
c:\mfta\q|hr-finance|c:\mfta\f;c:\mfta\g|txt;doc;xls|y|y|y|y
This is what I expect the new file to contain:
c:\mfta\t
c:\mfta\g
c:\mfta\a
c:\mfta\e
c:\mfta\q
This is my code:
StreamReader sr = wFile.OpenText();
while ((line = sr.ReadLine()) != null)
{
//TRIM at the '|'
string[] directory = line.Split('|');
Console.WriteLine(directory[0]);
// check for multiple directories
// seperated by semi colon (
int found = directory[0].IndexOf(";", 0);
if (found > -1)
{
Console.WriteLine("Multiple directory");
// bug here!!
string[] dirs = directory[0].Split(';');
for(int i = 0; i < dirs.Length; i++)
Console.WriteLine(dirs[0]);
}
else
Console.WriteLine(directory[0]);
}
sr.Close();
Please help, thanks in advance
Please help!!
I have the following text file, and I want to extract the first field (directory paths) of each line, and maybe write it to another file or an arraylist.
This is the file:
c:\mfta\t;c:\mfta\g|hr-admin|c:\mfta\s;c:\mfta\v|txt;doc;xls|n|n|y|y
c:\mfta\a;c:\mfta\e|hr-finance|c:\mfta\f;c:\mfta\g|txt;doc;xls|y|y|y|y
c:\mfta\q|hr-finance|c:\mfta\f;c:\mfta\g|txt;doc;xls|y|y|y|y
This is what I expect the new file to contain:
c:\mfta\t
c:\mfta\g
c:\mfta\a
c:\mfta\e
c:\mfta\q
This is my code:
StreamReader sr = wFile.OpenText();
while ((line = sr.ReadLine()) != null)
{
//TRIM at the '|'
string[] directory = line.Split('|');
Console.WriteLine(directory[0]);
// check for multiple directories
// seperated by semi colon (
int found = directory[0].IndexOf(";", 0);
if (found > -1)
{
Console.WriteLine("Multiple directory");
// bug here!!
string[] dirs = directory[0].Split(';');
for(int i = 0; i < dirs.Length; i++)
Console.WriteLine(dirs[0]);
}
else
Console.WriteLine(directory[0]);
}
sr.Close();
Please help, thanks in advance