-1

I am creating a list of subdirectories on a server that all have one subfolder name in common. The server isn't identified by a drive letter, but by a name. So, my current code is something like this:

List<string> directories = new List<string>();
directories.Add(@"\\homeserv\Data\CompanyA\ABCD");
directories.Add(@"\\homeserv\Data\CompanyB\ABCD");
...
directories.Add(@"\\remoteserv\data\CompanyC\Eastern\ABCD");

This is okay with only a few subdirectories, but what if we had hundreds? We don't want to hard-code all these subdirectories into the program. Is there a way to search all subdirectories on a server for similar names (ex: "ABCD"), and put all those subdirectory names into a List?

I found the following code, but it seems to want a drive letter (ex: "C:\" and isn't working with a server name (ex: "\homeserv").

string[] dirs = Directory.GetFiles(@"\\homeserv\", "ABCD");

Thank you!

John
  • 313
  • 5
  • 9
  • 2
    Maybe the *sharename* is *Data*. Have you tried `string[] dirs = Directory.GetFiles(@"\\homeserv\Data", "ABCD");` ? – L.B Nov 03 '16 at 18:13
  • if you're only interested in subfolders, try `GetDirectories` instead – Hambone Nov 03 '16 at 18:16

1 Answers1

0

You likely have to provide at least a Server Name and a Share Name - your example using Directory.GetFiles only provides the Server Name.

Try:

using System.IO; var remoteShare = new DirectoryInfo(@"\\homeserv\Data"); var subDirectories = remoteShare.GetDirectories();

Thracx
  • 403
  • 5
  • 8