471,120 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

Visual Studio 2005 Code Snippets is wrong (Search a Directory for Files Recursively)

You can download them here:
http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx

This snippet seems wrong:
Visual C# 2005 Code Snippets -filesystem -Search a Directory for
Files Recursively

I don't believe DirSearch will return any results for files in the
root directory originally passed to it. Am I right? Here's the code:

System.Collections.ArrayList files = new
System.Collections.ArrayList();
DirSearch(@"C:\", ref files);

//Method to Search Directory for specified file Type.Paste it outside
the function
public void DirSearch(string sDir, ref System.Collections.ArrayList
files)
{
try
{
foreach (string d in System.IO.Directory.GetDirectories(sDir))
{
foreach (string f in System.IO.Directory.GetFiles(d,
"*.txt"))
{
files.Add(f);
}
DirSearch(d, ref files);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}

Zytan

May 15 '07 #1
2 2688
On May 15, 9:47 am, Zytan <zytanlith...@gmail.comwrote:
You can download them here:http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx

This snippet seems wrong:
Visual C# 2005 Code Snippets -filesystem -Search a Directory for
Files Recursively

I don't believe DirSearch will return any results for files in the
root directory originally passed to it. Am I right? Here's the code:

System.Collections.ArrayList files = new
System.Collections.ArrayList();
DirSearch(@"C:\", ref files);

//Method to Search Directory for specified file Type.Paste it outside
the function
public void DirSearch(string sDir, ref System.Collections.ArrayList
files)
{
try
{
foreach (string d in System.IO.Directory.GetDirectories(sDir))
{
foreach (string f in System.IO.Directory.GetFiles(d,
"*.txt"))
{
files.Add(f);
}
DirSearch(d, ref files);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}

}

Zytan
I believe you are right. You can edit the snippet to correct if you
need to.

Chris

May 16 '07 #2
I believe you are right. You can edit the snippet to correct if you
need to.
Ok, thanks Chris.

Zytan

May 21 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by m.roello | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.