VB.NET中怎么对文件进行合并
本篇文章给大家分享的是有关VB.NET中怎么对文件进行合并,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
VB.NET文件合并代码实现示例:
Private Sub MergeFiles(ByVal
inputDir As String, ByVal
inputMask As String, ByVal
outputPath As String)'store files in datatable
with their created times
to sort by laterDim files As New DataTable
files.Columns.Add("filepath",
GetType(String))files.Columns.Add("creationtime",
GetType(Date))'find partial files
For Each f As String In IO.
Directory.GetFiles(inputDir, inputMask)files.Rows.Add(New Object()
{f, IO.File.GetCreationTime(f)})Next
'make sure output file does
not exist before writingIf IO.File.Exists(outputPath) Then
IO.File.Delete(outputPath)
End If
'loop through file in order,
and append contents to output fileFor Each dr As DataRow In
files.Select("", "creationtime")Dim contents As String =
My.Computer.FileSystem.ReadAllText
(CStr(dr("filepath")))My.Computer.FileSystem.WriteAllText
(outputPath, contents, True)Next
End Su
以上就是VB.NET中怎么对文件进行合并,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。