List Info

Thread: C-Sharp (C#) Group: Getting a list of files in a specific directory...




C-Sharp (C#) Group: Getting a list of files in a specific directory...
user name
2006-03-23 19:44:06
I know how to create, read and write files in C# now.  I
know how to
check if files exist before reading, etc.  What I'd like to
know is, is
there a way to get a list of files that are in a specific
directory in
C#?

For example, if I wanted to create a C# program that would
scan my
music folder for *.ogg files and then add the filenames to a
text file.
 How would I go about doing this?

Any help would be appreciated.

Sincerely,

Gordon E.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Getting a list of files in a specific directory...
user name
2006-03-23 19:49:52
The DirectoryInfo object is the way to go.  Assuming the string variable holding the directory name is "dir":

if (Directory.Exists(dir))
{
   DirectoryInfo di = new DirectoryInfo(dir);
   FileInfo [] files = di.GetFiles("*.ogg");
   foreach(FileInfo info in files)
   {
       ; // Do your thing
   }
}

The FileInfo object has the necessary properties to access the files.  Primarily the Name property, which is just the filename, and the FullName property which is the full path to the file, including directory and file name.

On 3/23/06, Gordon Ellsworth <gmail.com">grellsworthgmail.com> wrote:

I know how to create, read and write files in C# now.  I know how to
check if files exist before reading, etc.  What I'd like to know is, is
there a way to get a list of files that are in a specific directory in
C#?

For example, if I wanted to create a C# program that would scan my
music folder for *.ogg files and then add the filenames to a text file.
How would I go about doing this?

Any help would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )