Below is my code to get all files in large directory (Framework 3.5). It run ~ 1 hour, but cannot finish, memory in Task Manager upto 1,600,000K
void ApplyAllFiles(DirectoryInfo dir)
{
String space = " ";
foreach (FileInfo f in dir.GetFiles())
{
try
{
int size = Convert.ToInt32(f.Length / 1024);
if (size > filesize && isFileType(f.FullName) == true)
{
pw.WriteLine(f.LastWriteTime + space + size + space + f.FullName);
}
}
catch
{ }
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
try
{
ApplyAllFiles(d);
}
catch
{
}
}
}
If I use Java code, just 5 min for finish and memory always < 100,000 K. I think C# code maybe has problem (getFiles & getDirectories is not good for large Directory). I hope someone can help.
I SOLVED IT BY TAKE FOREACH LOOP INSIDE TRY { }.