Copying strings arrays to another from Directory.GetFiles

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I am trying to do multiple Directory.GetFiles and append the results to one
array that I will process. I tried this:

string[] strFiles;
strFiles = Directory.GetFiles(SemaSettings.InputFilePath, "GL*.*");
strFiles.CopyTo(Directory.GetFiles(SemaSettings.InputFilePath,
"IN.*"),strFiles.Length-1);
strFiles.CopyTo(Directory.GetFiles(SemaSettings.InputFilePath,
"TX.*"),strFiles.Length-1,);

I know I have this backwards but this is sort of what I am trying to do.

I want to do the GetFiles for "GL*.*" first and then do another with "IN.*"
and have the result get appended to the strFiles array and same for "TX.*".

Can I do this is just a couple of calls?

Thanks,

Tom
 
A quick solution (might not be better)
Use the generic list class for this problem.

string[] strFiles;
strFiles = Directory.GetFiles(SemaSettings.InputFilePath, "GL*.*");

List<string> files = new List<string>(strFiles);

files.AddRange(Directory.GetFiles(SemaSettings.InputFilePath,
"IN.*"));

files.AddRange(Directory.GetFiles(SemaSettings.InputFilePath,
"TX.*"));

HTH
Kalpesh
 
Back
Top