Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
string[] drives = Directory.GetLogicalDrives();
foreach (string d in drives)
{
string[] d1 = Directory.GetDirectories(d);
string[] pathlist = fde.Union(falaa).Union(d1).ToArray();
}

//fde is the nother path list
//falaa is the nother path list
* pathlist is the collection of all lists

//in path list i am not able to store the list
Posted
Comments
Member 10072552 12-May-15 6:19am    
what is the issue in this ?
Aditya Chauhan 12-May-15 6:30am    
actually in this i am just want to store the d1 list in the path list,

1 solution

Um...That's some odd code you have there.

Each time you go round the loop, you collect some information, and immediately throw it away - none of your data is available outside the loop as it goes out of scope when the loop ends, or available to the next iteration as you overwrite it with new variables - so the whole loop is currently redundant and can be removed.

I'm not exactly sure what you are trying to do, but to start with, move the first union outside the loop as nothing will change it:
C#
string[] drives = Directory.GetLogicalDrives();
string[] listPaths = fde.Union(falaa).ToArray();
foreach (string d in drives)
    {
    string[] d1 = Directory.GetDirectories(d);
    string[] pathlist = listPaths.Union(d1).ToArray();
    }
Then, I'd create an external list to hold the data while I was assembling it:
C#
string[] drives = Directory.GetLogicalDrives();
string[] listPaths = fde.Union(falaa).ToArray();
List<string> paths = new List<string>();
foreach (string d in drives)
    {
    string[] d1 = Directory.GetDirectories(d);
    paths.AddRange(listPaths.Union(d1));
    }
The paths collection is then available outside the loop.
 
Share this answer
 
Comments
Aditya Chauhan 12-May-15 6:43am    
but in this case i am getting duplicate data of list path
OriginalGriff 12-May-15 6:51am    
What are you actually trying to achieve?
Maciej Los 12-May-15 7:06am    
So, use: paths.Distinct() method to get unique values ;)
Aditya Chauhan 12-May-15 7:09am    
i am data duplicacy which data in list path that are show multiple times
OriginalGriff 12-May-15 7:22am    
No, not "what code are you using?" - "what task is the code meant to perform?"
What are you trying to get in the final collection?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900