VB.NET编程语言在文件的操作方面体现了非常大的作用。比如今天要为大家介绍的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 later
Dim 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 writing
If IO.File.Exists(outputPath) Then
IO.File.Delete(outputPath)
End If
'loop through file in order,
and append contents to output file
For 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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
VB.NET文件合并的相关实现方法就为大家介绍到这里。
【编辑推荐】