VB.Net实现文件合并的实例

 

VB.NET实现文件合并的实例
 

Code:
  1. Private Sub MergeFiles(ByVal inputDir As StringByVal inputMask As StringByVal outputPath As String)   
  2.   
  3.     
  4.     'store files in datatable with their created times to sort by later   
  5.   
  6.     Dim files As New DataTable   
  7.   
  8.     files.Columns.Add("filepath"GetType(String))   
  9.   
  10.     files.Columns.Add("creationtime"GetType(Date))   
  11.   
  12.     'find partial files   
  13.   
  14.     For Each f As String In IO.Directory.GetFiles(inputDir, inputMask)   
  15.   
  16.         files.Rows.Add(New Object() {f, IO.File.GetCreationTime(f)})   
  17.   
  18.     Next  
  19.   
  20.   
  21.   
  22.     'make sure output file does not exist before writing   
  23.   
  24.     If IO.File.Exists(outputPath) Then  
  25.   
  26.         IO.File.Delete(outputPath)   
  27.   
  28.     End If  
  29.   
  30.     
  31.   
  32.     'loop through file in order, and append contents to output file   
  33.   
  34.     For Each dr As DataRow In files.Select("""creationtime")   
  35.   
  36.         Dim contents As String = My.Computer.FileSystem.ReadAllText(CStr(dr("filepath")))   
  37.   
  38.         My.Computer.FileSystem.WriteAllText(outputPath, contents, True)   
  39.   
  40.     Next  
  41.   
  42.     
  43.   
  44. End Sub  

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值