轻松打造VB.NET文件合并示例

VB.NET编程语言在文件的操作方面体现了非常大的作用。比如今天要为大家介绍的VB.NET文件合并,就可以应用VB.NET来轻松的实现。大家就一起来具体的解读这段代码来对此进行一个详细的了解。

VB.NET文件合并代码实现示例:

 
 
 
  1. Private Sub MergeFiles(ByVal 
    inputDir As String, ByVal 
    inputMask As String, ByVal 
    outputPath As String)  
  2. 'store files in datatable 
    with their created times 
    to sort by later  
  3. Dim files As New DataTable  
  4. files.Columns.Add("filepath",
     GetType(String))  
  5. files.Columns.Add("creationtime",
     GetType(Date))  
  6. 'find partial files  
  7. For Each f As String In IO.
    Directory.GetFiles(inputDir, inputMask)  
  8. files.Rows.Add(New Object() 
    {f, IO.File.GetCreationTime(f)})  
  9. Next  
  10. 'make sure output file does
     not exist before writing  
  11. If IO.File.Exists(outputPath) Then  
  12. IO.File.Delete(outputPath)  
  13. End If  
  14. 'loop through file in order, 
    and append contents to output file  
  15. For Each dr As DataRow In 
    files.Select("", "creationtime")  
  16. Dim contents As String = 
    My.Computer.FileSystem.ReadAllText
    (CStr(dr("filepath")))  
  17. My.Computer.FileSystem.WriteAllText
    (outputPath, contents, True)  
  18. Next  
  19. End Su 

 VB.NET文件合并的相关实现方法就为大家介绍到这里。

【编辑推荐】

  1. VB.NET水晶报表优点及结果描述
  2. VB.NET指针在实际应用中作用体现
  3. VB.NET List实用技巧详解
  4. VB.NET文件名排序轻松掌握
  5. VB.NET IEnumerator接口操作代码解读
THE END