Best way to enumurate the following directories and files

I have bunch of directories at a certain paths in the following possible format:

C:\Program Files\Logic\DDC[ 0 ]

C:\Program Files\Logic\DDC[ 1]

C:\Program Files\Logic\DDC[2    ]

C:\Program Files\Logic\DDC[3]

I'd like to accomplish the following:

1)Enumurate all of numbered DDC directories and store their paths them in a List of String

I.E: List<String> ddcPaths -> should have:
ddcPaths[0] = "DDC[0]";
ddcPaths[1] = "DDC[1]";
ddcPaths[2] = "DDC[2]";

2)Enumurate all files directly under the DDC folder but nothing deeper than that

I.E: If DDC[0] has a.txt, b.txt and obj\c.txt, I should get
List<String> ddc_0 -> should have
ddc_0[0] = "a.txt";
ddc_0[1] = "b.txt";

I hope my explanation was clear enough but if something didn't make sense, please let me know.

Answers


If U have such data structure I suggest U should use one dictionary with directory name as key, and list of it's filenames as value. For example:

var ddcPaths = new Dictionary<string, List<string>>();
foreach (var directoryInfo in new DirectoryInfo(@"C:\Program Files\Logic\").GetDirectories())
{
    if (directoryInfo.Name.Contains("DDC["))
    {
         ddcPaths.Add(directoryInfo.Name, new List<string>());
         foreach (var fileInfo in directoryInfo.GetFiles())
         {
             ddcPaths[directoryInfo.Name].Add(fileInfo.FullName);
         }
    }
}

but you should notice than U cant get Dictionary value by int index, only by key, declared in this dictionary (folder name in our case). But if U don't want to do like this U can do the following:

var ddcPaths = new List<string>();
var filePaths = new List<List<string>>();

foreach (var directoryInfo in new DirectoryInfo(@"C:\Program Files\Logic\").GetDirectories())
{
   if (directoryInfo.Name.Contains("DDC["))
   {
       ddcPaths.Add(directoryInfo.Name);
       var tempList = new List<string>();
       foreach (var fileInfo in directoryInfo.GetFiles())
       {
           tempList.Add(fileInfo.FullName);
       }
       filePaths.Add(tempList);
    }
}

but in this case U use two different data structures to represent related data. I suggest it would be logically to use dictionary.


Need Your Help

How does java.util.concurrent classes reuse threads?

java multithreading concurrency

I'm talking about the Thread instances, if they get their Runnable provided as a constructor argument and you can only execute their start method once, how come the Executor* family of classes reuse

Switch on EnumSet

java enums switch-statement bit-fields enumset

The old way, if we wanted to switch on some complicated bitmask, we could easily do it like this (a random example from the top of my head just to demonstrate the issue):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.