473,554 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.ArrayList files = new
System.Collecti ons.ArrayList() ;
DirSearch(@"C:\ ", ref files);

//Method to Search Directory for specified file Type.Paste it outside
the function
public void DirSearch(strin g sDir, ref System.Collecti ons.ArrayList
files)
{
try
{
foreach (string d in System.IO.Direc tory.GetDirecto ries(sDir))
{
foreach (string f in System.IO.Direc tory.GetFiles(d ,
"*.txt"))
{
files.Add(f);
}
DirSearch(d, ref files);
}
}
catch (System.Excepti on excpt)
{
Console.WriteLi ne(excpt.Messag e);
}
}

Zytan

May 15 '07 #1
2 2924
On May 15, 9:47 am, Zytan <zytanlith...@g mail.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.Collecti ons.ArrayList files = new
System.Collecti ons.ArrayList() ;
DirSearch(@"C:\ ", ref files);

//Method to Search Directory for specified file Type.Paste it outside
the function
public void DirSearch(strin g sDir, ref System.Collecti ons.ArrayList
files)
{
try
{
foreach (string d in System.IO.Direc tory.GetDirecto ries(sDir))
{
foreach (string f in System.IO.Direc tory.GetFiles(d ,
"*.txt"))
{
files.Add(f);
}
DirSearch(d, ref files);
}
}
catch (System.Excepti on excpt)
{
Console.WriteLi ne(excpt.Messag e);
}

}

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
6158
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 itself. Everything you need is available at no costs (except download hassle and installation time). Once your system is set up properly its just a matter...
0
2575
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: OSTDLL, Configuration: Debug Win32 ------ Compiling... StdAfx.cpp
16
2569
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 gradual upgrade of my web programming skills from Classic ASP / VBS to ASP.NET / VB.NET. While the study of the language differences and all the new...
54
6401
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 quickly and easly." I don't agree on what concernes ASP .NET Web Sites in VS2005. All what involves Namespaces in Web sites has been disappeared....
12
1846
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 "*.html" file, it starts a new thread to go to work on that file. Since each individual thread doesn't have to touch another's file, this works fine. ...
12
5882
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/ folder in the same directory as the source code. However, in Visual Studio .NET 2005 when I selected 'Publish Web Site' and selected a target...
1
2090
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 and if successful, creates a directory on the web server. I was using Transaction Scope to accomplish this action; here is the code excerpt: '...
1
2871
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 file which includes some html code to populate html formatted content as the text of an asp:label (<asp:label>). The reading of the text file itself...
0
7311
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 beginning CIS student who is struggling to get their programs working. I work in the computer lab at the college I'm attending and I see many students who...
0
7493
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7775
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7854
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6113
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3525
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1107
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.