Re: Creating same new DirectoryInfo in loop?
From: Peter Rilling (peter_at_nospam.rilling.net)
Date: 08/07/04
- Next message: Sreejith S S Nair: "Views"
- Previous message: Mohammad-Reza: "Execute an external application in my program"
- In reply to: Vagabond Software: "Creating same new DirectoryInfo in loop?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Aug 2004 23:27:15 -0700
I do not see a problem with that. The old objects will be destroyed when
garbage collection happens (as long as no other references exist, which it
looks like there is not).
As a side not, you might get cleaner code using a Queue object (not that
anything is wrong with your code, just an observation), that way you can
just Enqueue and Dequeue your items.
"Vagabond Software" <carlfenley-X-@-X-san.rr.com> wrote in message
news:OErdo6CfEHA.1604@TK2MSFTNGP11.phx.gbl...
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);
}
- Next message: Sreejith S S Nair: "Views"
- Previous message: Mohammad-Reza: "Execute an external application in my program"
- In reply to: Vagabond Software: "Creating same new DirectoryInfo in loop?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|