Click here to Skip to main content
15,890,882 members
Home / Discussions / C#
   

C#

 
GeneralRe: Recursive directory search Pin
electriac15-Jan-07 21:52
electriac15-Jan-07 21:52 
GeneralRe: Recursive directory search Pin
Luc Pattyn15-Jan-07 22:22
sitebuilderLuc Pattyn15-Jan-07 22:22 
AnswerRe: Recursive directory search Pin
Christian Graus15-Jan-07 21:48
protectorChristian Graus15-Jan-07 21:48 
GeneralRe: Recursive directory search Pin
electriac15-Jan-07 21:54
electriac15-Jan-07 21:54 
GeneralRe: Recursive directory search Pin
Christian Graus15-Jan-07 22:00
protectorChristian Graus15-Jan-07 22:00 
GeneralRe: Recursive directory search Pin
electriac15-Jan-07 22:09
electriac15-Jan-07 22:09 
AnswerRe: Recursive directory search Pin
Luc Pattyn15-Jan-07 22:27
sitebuilderLuc Pattyn15-Jan-07 22:27 
GeneralRe: Recursive directory search Pin
electriac16-Jan-07 0:21
electriac16-Jan-07 0:21 
I have revised my program to examine all the files on the C: drive. I have placed the files in a sorted list box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
//using System.Net;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        static int countFiles = 0;
        public Form1()
        {
            InitializeComponent();
        }
        ArrayList list = new ArrayList();
     //--------------------------------------------------------// 
     //------There is something wrong with this function ------//
     //--------------------------------------------------------//
        void DirSearch(string sDir)
        {
            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    foreach (string f in Directory.GetFiles(d, "*.*"))
                    {
                        list.Add(f);
                        countFiles++;
                    }
                    DirSearch(d);
                }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
        }
      //------------------------------------------------------//  
        private void button1_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            listBox1.Items.Clear();
            listBox1.Sorted = true;
            list.Clear();
            countFiles = 0;
            DirSearch("c:\\");
            foreach (string s in list) listBox1.Items.Add(s);
            listBox1.Items.Add(" --> Number Of Files = " + countFiles);
            this.Cursor = Cursors.Default;
        }
    }
}


When I run this code all directories begining with the letter 't' or more are NOT present this includes the "Windows" directory. I have now tested this on four different machines all of which report the same erroneus result. A directory called "system" is found and one called "text" is not.
GeneralRe: Recursive directory search Pin
Luc Pattyn16-Jan-07 1:14
sitebuilderLuc Pattyn16-Jan-07 1:14 
GeneralRe: Recursive directory search Pin
electriac16-Jan-07 1:31
electriac16-Jan-07 1:31 
GeneralRe: Recursive directory search Pin
Luc Pattyn16-Jan-07 1:31
sitebuilderLuc Pattyn16-Jan-07 1:31 
GeneralRe: Recursive directory search Pin
electriac16-Jan-07 1:36
electriac16-Jan-07 1:36 
GeneralRe: Recursive directory search Pin
Luc Pattyn16-Jan-07 2:20
sitebuilderLuc Pattyn16-Jan-07 2:20 
GeneralRe: Recursive directory search Pin
Luc Pattyn16-Jan-07 2:46
sitebuilderLuc Pattyn16-Jan-07 2:46 
AnswerRe: Recursive directory search Pin
davidc2p16-Jan-07 6:03
davidc2p16-Jan-07 6:03 
GeneralRe: Recursive directory search Pin
electriac16-Jan-07 9:32
electriac16-Jan-07 9:32 
GeneralRe: Recursive directory search Pin
Luc Pattyn16-Jan-07 10:12
sitebuilderLuc Pattyn16-Jan-07 10:12 
GeneralRe: Recursive directory search [modified] Pin
electriac12-Feb-07 1:57
electriac12-Feb-07 1:57 
Questionhow to import a dll in Windows Service Pin
ramyasangeet15-Jan-07 19:35
ramyasangeet15-Jan-07 19:35 
QuestionSingle web form project Pin
Mohammad Daba'an15-Jan-07 19:35
Mohammad Daba'an15-Jan-07 19:35 
AnswerRe: Single web form project Pin
Christian Graus15-Jan-07 21:44
protectorChristian Graus15-Jan-07 21:44 
GeneralRe: Single web form project Pin
davidc2p16-Jan-07 6:06
davidc2p16-Jan-07 6:06 
GeneralRe: Single web form project Pin
Mohammad Daba'an16-Jan-07 19:56
Mohammad Daba'an16-Jan-07 19:56 
GeneralRe: Single web form project Pin
Christian Graus16-Jan-07 20:12
protectorChristian Graus16-Jan-07 20:12 
GeneralRe: Single web form project Pin
Mohammad Daba'an16-Jan-07 20:20
Mohammad Daba'an16-Jan-07 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.