|
-
May 11th, 2005, 04:49 AM
#1
Thread Starter
Lively Member
Get folder contents
Hi
How can I get the files in a folder - but only certain file types eg only txt file?
Thanks
-
May 11th, 2005, 05:11 AM
#2
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:
Dim dir As DirectoryInfo = New DirectoryInfo("C:\")
Dim f As FileInfo() = dir.GetFiles("*.txt")
For Each t As FileInfo In f
Console.WriteLine(t.Name)
Next
-
May 19th, 2005, 02:46 PM
#3
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?
-
May 20th, 2005, 09:16 AM
#4
-
May 24th, 2005, 12:26 AM
#5
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?
-
May 24th, 2005, 12:56 AM
#6
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
-
May 24th, 2005, 11:44 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|