Results 1 to 7 of 7

Thread: Get folder contents

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    123

    Get folder contents

    Hi

    How can I get the files in a folder - but only certain file types eg only txt file?

    Thanks
    Beware of the Dog

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Get folder contents

    Code:
    DirectoryInfo dir = new DirectoryInfo("C:\\");
    FileInfo[] f = dir.GetFiles("*.txt");
    foreach(FileInfo t in f){
       Console.WriteLine(t.Name);
    }
    Edit:
    I have to stop putting C# code in the VB.Net section
    VB Code:
    1. Dim dir As DirectoryInfo = New DirectoryInfo("C:\")
    2. Dim f As FileInfo() = dir.GetFiles("*.txt")
    3. For Each t As FileInfo In f
    4.     Console.WriteLine(t.Name)
    5. Next

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Get folder contents

    I've got an odd problem. When I use:
    dir.GetFiles("2003*.*")
    one of my results is:
    2011001XEAP_1_1.837
    This also happens in a command line dir search. Any idea?

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Get folder contents

    ????

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Get folder contents

    I created this file at home (using XP Pro), and dir does not return filenames that do not match. I'm using 2000 Pro at work. Is this a bug, or am I missing something simple?

  6. #6
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Get folder contents

    hmm... I created two files.... "2011001XEAP_1_1.837" and "2003001XEAP_1_1.837"

    only the latter came up in both.

    are these the names including the extension?
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  7. #7
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Get folder contents

    I think it has something to do with the number of files in the directory. 837 is the file extension.

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