select files by multiple extension name

The default selectfile's selectpattern only support on exention name.

For example,  command below can only retrieve jpg image.

If you want both jpg and gif, you need two clause and combine the outputs.  

System.IO.Directory.GetFiles( " F:\ " " *.jpg " , IO.SearchOption.AllDirectories)

 


Alternatively, you can use LINQ and regular expression like below, but the code has issue when image has two extension like "Signature.jpg.pfs". Need a bit more works on the regular expression.

If someone knows how to write the regular expression, please let me know. Thanks 

ExpandedBlockStart.gif 代码
Private   Sub  loadFiles() 
        
For   Each  afile  In  SelectFilesWithExtenstions( " F:\Learning\LoadDistinctFileInCheckListBox\file " " .jpg|.png|.gif " )
            Debug.Print(afile.name)
        
Next
    
End Sub

    
Private   Function  SelectFilesWithExtenstions( ByVal  folder  As   String ByVal  extensions  As   String
        
Dim   dir   As   New  System.IO.DirectoryInfo(folder)
        
Dim  fileList  =   dir .GetFiles( " *.* " , System.IO.SearchOption.AllDirectories)
        
Dim  searchExtenstions  As  System.Text.RegularExpressions.Regex  =   New  System.Text.RegularExpressions.Regex((extensions))
        
Dim  queryGroupByExt  =  From afile  In  fileList _
                                Let matches 
=  searchExtenstions.Matches(afile.FullName) _
                                Where (searchExtenstions.Matches(afile.FullName).Count 
>   0 ) _
                                
Select  Name  =  afile.FullName, _
                                Matches 
=  From match  As  System.Text.RegularExpressions.Match  In  matches _
                                
Select  match.Value
        
Return  queryGroupByExt
    
End Function

 

 

 

转载于:https://www.cnblogs.com/yangbin990/archive/2011/02/04/1949118.html

你可能感兴趣的:(select files by multiple extension name)