473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2910
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Martin Bless | last post by:
The good news: Along with Python-2.4 comes really good news to Windows users. Yes, you now CAN build extension modules yourself using the SAME C++ compiler and linker Python is built with...
0
by: gerd | last post by:
Hello, I want to port an MFC Application from Visual Studio 6 MFC application to Visual C++ 2005 express edition beta. While building i get following error: ------ Build started: Project:...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
54
by: m.roello | last post by:
In the book: "Working with Microsoft Visual Studio 2005" Craig Skibo wrote: "The power of Visual Studio 2005 lies in its ability to empower users to build, test, and debug powerful applications...
12
by: David Beoulve | last post by:
In my windows C# app, I create a thread to separate the main code block from the GUI, which recursively sorts through all the directories starting from a given point, and every time it finds a...
12
by: Nathan Sokalski | last post by:
I recently upgraded to from Visual Studio .NET 2003 to Visual Studio .NET 2005. In Visual Studio .NET 2003 when I would select 'Build' it would add a *.dll with the name of the Project to a /bin/...
1
by: =?Utf-8?B?Sm9l?= | last post by:
Very weird; I lost a day worth of work because of this problem. I have an ASP.NET application written in VB that is using MySQL database. Shortly, a page creates a Customer record in the database...
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.