Reputation: 2331
I'm confronted with a design problem in my attempt to populate my datagridview
with simple files.
I've declared a main directory in my Settings
file. I need my datagridview
to search through this parent directory in 7 subfolders. Each subfolder has a bunch of subfolders (names of machines I am managing). Each of those has contained in it the file I need to add to my grid.
Example:
C:\Users\me\Documents\MASTERDIRECTORY\Folder7\Machine Name1\file.txt
C:\Users\me\Documents\MASTERDIRECTORY\Folder7\Machine Name2\file.txt
Obviously some kind of recursive code is needed to perform the search, but how should I start? Performance wise, should I add these file paths to an array list and then translate that to my grid?
Upvotes: 0
Views: 469
Reputation: 8640
Something like this may help :-
string filePath = @"C:\Users\me\Documents\MASTERDIRECTORY\Folder7"
foreach (string Folder in Directory.GetDirectories(filePath))
{
foreach (string file in Directory.GetFiles(Folder))
{
// here you can grab the log file path and add it to you Gridview
}
}
Upvotes: 1