Multiple file-extensions searchPattern for System.IO.Directory.GetFiles

This article will show you to get multiple file-extension search pattern, in regular way you can get files with specific extensions but using same how to get Multiple file-extension, basically we are querying on the list file and get only required extension files. Even you can use regular expression for search pattern, here is code


    var filteredFiles = System.IO.Directory.GetFiles(directory.FullName, "*.*").Where(file => file.ToLower().EndsWith("zip") || file.ToLower().EndsWith("rar") || file.ToLower().EndsWith("7z")).ToList();
    foreach (var Fi in filteredFiles)
    {
        FileInfo fi = new FileInfo(Fi.ToString());
    }

Advertisements
This entry was posted in C#.NET, MVC and tagged . Bookmark the permalink.

One Response to Multiple file-extensions searchPattern for System.IO.Directory.GetFiles

  1. Ram says:

    Thank you very much for posting the simplest solution to retrieve multiple extension files from the folder.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s