V
Vagabond Software
I am recursing through ALL folders and sub-folders below a certain level to list all the files of a certain type in those folders. I use two ArrayLists, alFiles and alFolders, to track matching files and my progress in the recursion.
I use a while loop to manage the folder-subfolder drill-down. Each pass through the while loop creates a new DirectoryInfo object named currentFolder.
Is there are problem with that? Does this create multiple objects or does it destroy the existing DirectoryInfo object and create a new one?
Here is the relevant source:
ArrayList alFiles = new ArrayList();
ArrayList alFolders = new ArrayList();
FileInfo[] files;
alFolders.Add(rootPath);
while(alFolders.Count > 0)
{
DirectoryInfo currentFolder = new DirectoryInfo(alFolders[0].ToString());
folders = currentFolder.GetDirectories();
foreach(DirectoryInfo subFolder in folders)
alFolders.Add(currentFolder.FullName + "\\" + subFolder.Name);
files = currentFolder.GetFiles();
foreach(FileInfo file in files)
{
if (file.Name.EndsWith("xml"))
alFiles.Add(file.Name);
}
alFolders.RemoveAt(0);
}
I use a while loop to manage the folder-subfolder drill-down. Each pass through the while loop creates a new DirectoryInfo object named currentFolder.
Is there are problem with that? Does this create multiple objects or does it destroy the existing DirectoryInfo object and create a new one?
Here is the relevant source:
ArrayList alFiles = new ArrayList();
ArrayList alFolders = new ArrayList();
FileInfo[] files;
alFolders.Add(rootPath);
while(alFolders.Count > 0)
{
DirectoryInfo currentFolder = new DirectoryInfo(alFolders[0].ToString());
folders = currentFolder.GetDirectories();
foreach(DirectoryInfo subFolder in folders)
alFolders.Add(currentFolder.FullName + "\\" + subFolder.Name);
files = currentFolder.GetFiles();
foreach(FileInfo file in files)
{
if (file.Name.EndsWith("xml"))
alFiles.Add(file.Name);
}
alFolders.RemoveAt(0);
}