Programming 笔记

工作中遇到的问题就记载这里

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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 

代码
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 StringByVal 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

 

 

 

posted on 2011-02-04 11:21  IT 笔记  阅读(238)  评论(0编辑  收藏  举报