all groups > c# > january 2008 >
You're in the

c#

group:

Copying strings arrays to another from Directory.GetFiles


Copying strings arrays to another from Directory.GetFiles tshad
1/31/2008 5:10:46 PM
c#:
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

Re: Copying strings arrays to another from Directory.GetFiles Kalpesh Shah
2/1/2008 11:06:19 AM
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
AddThis Social Bookmark Button