Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Extenstions

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
Id like to find out if a folder contains any files with a certain Extenstion. Can anyone help?

Thanks
 
For those interested, this will work.

Replace Environment.SystemDirectory with the string of the directory you want and "*.dll" with a string of * plus the extension you are searching for. Then, just loop through and do what you want with the files.

Code:
      using System;
      using System.Console;
      using System.IO;

      DirectoryInfo mDir = new DirectoryInfo(Environment.SystemDirectory);

      FileInfo[] mFileInfo = mDir.GetFiles("*.dll");

      foreach (FileInfo mFile in mFileInfo)
      {
        Console.WriteLine(mFile.Name);
      }

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top