C
Craig Lister
I am trying to get a list of all files in a directory (Recursivly).
The way I am trying to do it, it looks like I need to add an array of items
to an array of items. The way I am ACTUALLY doing it doesn't work... The
code where I *attempt* to add the two arrays together is wrong... it's just
code to show what I am trying to do..
Also, is this a good way to do what I am attempting to do ?
The 'ClassFiles' class isn't shown in this code.
private ArrayList GetFiles( string DirectoryName )
{
ArrayList myArray = new ArrayList(); // Return type. Will hold list
of all Objects
DirectoryInfo di = new DirectoryInfo(DirectoryName);
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo diNext in dirs)
{
myArray = myArray + GetFiles(diNext.FullName); // NO!
}
FileInfo[] rgFiles = di.GetFiles("*.*");
foreach (FileInfo fi in rgFiles)
{
ClassFiles FileObject = new ClassFiles();
FileObject.FileName = fi.FullName;
FileObject.FileSize = fi.Length;
FileObject.FileDateTime = fi.LastWriteTime;
myArray.Add(FileObject);
}
return myArray;
}
The way I am trying to do it, it looks like I need to add an array of items
to an array of items. The way I am ACTUALLY doing it doesn't work... The
code where I *attempt* to add the two arrays together is wrong... it's just
code to show what I am trying to do..
Also, is this a good way to do what I am attempting to do ?
The 'ClassFiles' class isn't shown in this code.
private ArrayList GetFiles( string DirectoryName )
{
ArrayList myArray = new ArrayList(); // Return type. Will hold list
of all Objects
DirectoryInfo di = new DirectoryInfo(DirectoryName);
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo diNext in dirs)
{
myArray = myArray + GetFiles(diNext.FullName); // NO!
}
FileInfo[] rgFiles = di.GetFiles("*.*");
foreach (FileInfo fi in rgFiles)
{
ClassFiles FileObject = new ClassFiles();
FileObject.FileName = fi.FullName;
FileObject.FileSize = fi.Length;
FileObject.FileDateTime = fi.LastWriteTime;
myArray.Add(FileObject);
}
return myArray;
}