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

开发 后端
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接口操作代码解读
责任编辑:曹凯 来源: 中国IT实验室
相关推荐

2010-01-11 15:12:30

VB.NET特殊窗体

2009-10-29 15:02:04

VB.NET文件排序

2010-01-14 10:07:08

VB.NET文件名排序

2009-10-27 16:18:58

VB.NET复制删除文

2010-01-13 18:28:21

VB.NET历史菜单

2009-11-03 09:37:33

VB.NET重载

2010-01-18 15:01:02

VB.NET异常迭代捕

2009-10-30 14:45:42

Flash控制VB.N

2010-01-13 17:47:59

VB.NET拖放

2010-01-14 13:59:01

2009-10-29 16:36:49

VB.NET .DLL

2010-01-11 18:40:03

VB.NET操作注册表

2010-01-18 19:36:52

VB.NET调整控件

2010-01-19 17:03:25

VB.NET可执行语句

2010-01-08 10:48:05

VB.NET多线程

2009-10-28 17:08:57

VB.NET数据库开发

2010-01-14 13:08:37

VB.NET运算符

2009-10-29 15:16:02

VB.NET文件传送

2009-11-02 12:35:10

VB.NET追加文件

2010-01-21 10:12:57

VB.NET控件自动排
点赞
收藏

51CTO技术栈公众号