moderator99
Member
- Joined
- Mar 9, 2021
- Messages
- 8
- Programming Experience
- Beginner
I'm not sure where to post this, so I'll post it here. Let me know if there's a better forum for me to post in.
I'm using Visual Studio 2019, creating a Windows Forms App under the .NET Framework in C#.
Here is my code at the moment:
This is just part of a test program I made as I try to create a faster directory search routine that avoids reading through certain directories.
What I'm wanting to do is instead of adding the output from Directory.GetFiles to a list and creating a new string array for each iteration of the first foreach loop, I want to append the output to the same string array (filePaths) during each iteration of the first foreach loop. The listbox is only being used to view the output while I develop the directory search routine. What I need is a string array as the final result, to be used in a different program I've already pretty much finished developing that requires the output to be in a string array.
Please forgive my lack of understanding of the basic language protocols. I'm relatively new to programming. I've looked online for help and checked through the documentation, but I fail to find a solution to my problem.
I'm using Visual Studio 2019, creating a Windows Forms App under the .NET Framework in C#.
Here is my code at the moment:
C#:
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string dir = fbd.SelectedPath;
string[] dirPaths = Directory.GetDirectories(dir, "*.*", SearchOption.AllDirectories).Where(d => !d.EndsWith("_files") && !d.Contains("_files\\")).ToArray();
foreach (string d in dirPaths)
{
string[] filePaths = Directory.GetFiles(d, "*.*", SearchOption.TopDirectoryOnly);
foreach (string f in filePaths)
{
listBox1.Items.Add(f);
listBox1.Update();
}
}
}
}
This is just part of a test program I made as I try to create a faster directory search routine that avoids reading through certain directories.
What I'm wanting to do is instead of adding the output from Directory.GetFiles to a list and creating a new string array for each iteration of the first foreach loop, I want to append the output to the same string array (filePaths) during each iteration of the first foreach loop. The listbox is only being used to view the output while I develop the directory search routine. What I need is a string array as the final result, to be used in a different program I've already pretty much finished developing that requires the output to be in a string array.
Please forgive my lack of understanding of the basic language protocols. I'm relatively new to programming. I've looked online for help and checked through the documentation, but I fail to find a solution to my problem.