|
-
Mar 28th, 2006, 06:50 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Finding the file-list of all files contained in a Folder
Does anyone know how to find the list of files from a folder in a directory?
Jennifer
-
Mar 28th, 2006, 07:07 AM
#2
Re: Finding the file-list of all files contained in a Folder
An easy way would to use the DirectoryInfo class.
Code:
//get the Folder
System.IO.DirectoryInfo myFolder = new System.IO.DirectoryInfo(@"C:\");
//loop through each file and delete
foreach (System.IO.FileInfo hFile in myFolder.GetFiles())
MesssageBox.Show(hFile.Name);
Edit--
Did I post VB.NET Code?
Last edited by Shuja Ali; Mar 28th, 2006 at 07:10 AM.
Reason: Posted VB Code earlier.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 28th, 2006, 07:25 AM
#3
Re: Finding the file-list of all files contained in a Folder
I see a lot of people recommend the use of the DirectoryInfo and FileInfo classes for this type of thing. While there is nothing really wrong with that, I'd consider it preferable to use the Directory and File classes. These two classes have all static members and thus do not require creation of an instance. Unless you need the extra functionality provided by the FileInfo class, like file size, I'd suggest going with the more efficient option.
Code:
foreach (string filePath in Directory.GetFiles(@"C:\"))
{
MessageBox.Show(filePath)
}
-
Mar 28th, 2006, 07:30 AM
#4
Re: Finding the file-list of all files contained in a Folder
Agreed.
I had this code handy as I have to do other stuff with the Files. So I just posted that with a small change.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 28th, 2006, 07:42 AM
#5
Thread Starter
Hyperactive Member
Re: Finding the file-list of all files contained in a Folder
Thanks Guys, its worked fine!!!!! - jennifer
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
|