輕松打造VB.NET文件合并示例
作者:佚名
VB.NET文件合并這一操作方法,在文件操作中是一個比較常見的操作。大家可以跟隨本文給出的代碼示例,進行一番實踐編寫,加深對此的印象。
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
VB.NET文件合并的相關實現方法就為大家介紹到這里。
【編輯推薦】
責任編輯:曹凱
來源:
中國IT實驗室