CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Help for a C# newbie - Recursive File Search

    I am new to .net - came from a PHP background and have little familiarity with the framework. But I am getting up to speed.

    I would like to learn from example.

    What if I would like to:

    1) Get a list of all *.bat files in both the current directory AND all subdirectories
    2) Populate listbox1 with the list of batch files - sorted alphabetically
    3) Create an EventHandler so that when a user double clicks on the batch file it opens automagically

    Care to show me your mastery?
    Last edited by altosax; February 23rd, 2006 at 03:10 PM. Reason: title bad

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Help for a C# newbie - Recursive File Search

    Sounds like you already know what you need : you just need pointing in the right direction.

    (1) The System.IO.Directory class will give you all the necessary functionality to do a recursive search. Look at the GetFiles() and GetDirectories() methods.

    (2) You need to fill an ArrayList with all the filenames. Sorting should be left up to the ListBox.

    (3) You can hook into the double click event on the ListBox and handle it.

    Also, the ListBox.Items.Add takes an object - not a string. This means you can add any class you want into it. The displayed string as well as the sorting works on the ToString() virtual function from System.Object for whatever class you decide to use as your element class.

    This should get you started.

    When you reply please keep your questions to distinct problems rather than your last post - it has a "please write this for me" feel to it.

    Darwen.
    Last edited by darwen; February 23rd, 2006 at 05:01 PM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured