Click here to Skip to main content
15,891,375 members
Home / Discussions / C#
   

C#

 
GeneralRe: I/O Threading Pin
Robert Rohde19-Apr-06 4:54
Robert Rohde19-Apr-06 4:54 
QuestionebXML message with C# Windows App Pin
Paul Brower18-Apr-06 2:54
Paul Brower18-Apr-06 2:54 
Questionhow to disable tree node in a dataset Pin
A4ad18-Apr-06 2:35
A4ad18-Apr-06 2:35 
AnswerRe: how to disable tree node in a dataset Pin
Robert Rohde18-Apr-06 5:47
Robert Rohde18-Apr-06 5:47 
GeneralRe: how to disable tree node in a dataset Pin
A4ad18-Apr-06 23:42
A4ad18-Apr-06 23:42 
Questionselect all the text in the textbox c# winform Pin
fady_sayegh18-Apr-06 2:19
fady_sayegh18-Apr-06 2:19 
AnswerRe: select all the text in the textbox c# winform Pin
Ed.Poore18-Apr-06 3:57
Ed.Poore18-Apr-06 3:57 
AnswerRe: select all the text in the textbox c# winform Pin
Eric Dahlvang18-Apr-06 4:52
Eric Dahlvang18-Apr-06 4:52 
AnswerRe: select all the text in the textbox c# winform Pin
Josh Smith18-Apr-06 5:25
Josh Smith18-Apr-06 5:25 
GeneralRe: select all the text in the textbox c# winform Pin
fady_sayegh18-Apr-06 6:27
fady_sayegh18-Apr-06 6:27 
AnswerRe: select all the text in the textbox c# winform Pin
LongRange.Shooter18-Apr-06 10:31
LongRange.Shooter18-Apr-06 10:31 
QuestionC# and Crystal Report Pin
Abhijeet Ballal18-Apr-06 1:16
Abhijeet Ballal18-Apr-06 1:16 
Questionworking with strings Pin
shezh18-Apr-06 0:42
shezh18-Apr-06 0:42 
AnswerRe: working with strings Pin
alexey N18-Apr-06 0:51
alexey N18-Apr-06 0:51 
AnswerRe: working with strings Pin
Stefan Troschuetz18-Apr-06 0:52
Stefan Troschuetz18-Apr-06 0:52 
GeneralRe: working with strings Pin
alexey N18-Apr-06 1:25
alexey N18-Apr-06 1:25 
GeneralRe: working with strings Pin
Stefan Troschuetz18-Apr-06 2:06
Stefan Troschuetz18-Apr-06 2:06 
AnswerRe: working with strings Pin
shezh18-Apr-06 3:53
shezh18-Apr-06 3:53 
Questiona weird problem in a member's setter. Pin
Green Fuze18-Apr-06 0:13
Green Fuze18-Apr-06 0:13 
AnswerRe: a weird problem in a member's setter. Pin
J4amieC18-Apr-06 0:18
J4amieC18-Apr-06 0:18 
GeneralRe: a weird problem in a member's setter. Pin
Green Fuze18-Apr-06 0:25
Green Fuze18-Apr-06 0:25 
QuestionLooping through Folders Pin
Pietman Kahl18-Apr-06 0:09
professionalPietman Kahl18-Apr-06 0:09 
Howzit people,

I sit with a very interesting problem and I have the feeling that there is an easier way to do what I want to do. In short, I want to loop through the folders on my machine and build a treeview. Here is the code that I use to do it but it is really slow (Windows form with 2 treeviews named tvwSource and tvwDestination):

<br />
    private void MainForm_Load(object sender, EventArgs e) {<br />
      string path = System.Reflection.Assembly.GetCallingAssembly().Location;<br />
      if (tvwSource.Nodes.Count == 0) {<br />
        FillTree(ref tvwSource, path);<br />
      }<br />
      try {<br />
        if (tvwDestination.Nodes.Count == 0) {<br />
          foreach (TreeNode treeNode in tvwSource.Nodes) {<br />
            tvwDestination.Nodes.Add((TreeNode)treeNode.Clone());<br />
          }<br />
        }<br />
      } catch (Exception) {<br />
      }<br />
    }<br />
<br />
    private void FillTree(ref TreeView bindingTree, string path) {<br />
      TreeNode rootNode = bindingTree.Nodes.Add("", "My Computer", "mycomputer");<br />
      foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) {<br />
        if (driveInfo.DriveType == DriveType.Fixed) {<br />
          LoopFolders(driveInfo.RootDirectory, ref rootNode);<br />
        }<br />
      }<br />
      try {<br />
        bindingTree.SelectedNode = bindingTree.Nodes.Find(path, true)[0];<br />
      } catch (IndexOutOfRangeException) {<br />
        if (bindingTree.Nodes.Count > 0) {<br />
          bindingTree.SelectedNode = bindingTree.Nodes[0];<br />
        }<br />
      }<br />
    }<br />
<br />
    private void LoopFolders(DirectoryInfo directoryInfo, ref TreeNode parentNode) {<br />
      try {<br />
        //Console.WriteLine("{0} ({1})", directoryInfo.FullName, directoryInfo.Attributes);<br />
        //TreeNode subNode = parentNode.Nodes.Add(directoryInfo.FullName, directoryInfo.Name);<br />
        TreeNode subNode = parentNode.Nodes.Add(directoryInfo.Name);<br />
        //Console.WriteLine(" - Added \"{0}\" to \"{1}\"", subNode.Text, parentNode.Text);<br />
        DirectoryInfo[] subDirectoryInfoArray = directoryInfo.GetDirectories();<br />
        foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfoArray) {<br />
          if (0 == (subDirectoryInfo.Attributes & (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Temporary))) {<br />
            if (0 < (subDirectoryInfo.Attributes & FileAttributes.Directory)) {<br />
              LoopFolders(subDirectoryInfo, ref subNode);<br />
            }<br />
          }<br />
        }<br />
        subDirectoryInfoArray = null;<br />
      } catch (UnauthorizedAccessException) {<br />
      } catch (IOException) {<br />
      } finally {<br />
      }<br />
    }<br />


Does anyone know of a quicker way to loop through all the directories on the filesystem?


I used to be vain.... BUT now I'm perfect!

-- modified at 6:11 Tuesday 18th April, 2006
AnswerRe: Looping through Folders Pin
alexey N18-Apr-06 0:49
alexey N18-Apr-06 0:49 
QuestionExtending WebBrowser in .Net 2.0 Pin
mustafakahraman17-Apr-06 23:43
mustafakahraman17-Apr-06 23:43 
AnswerRe: Extending WebBrowser in .Net 2.0 Pin
alexey N18-Apr-06 0:53
alexey N18-Apr-06 0:53 

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.