輕松打造VB.NET文件合并示例
作者:佚名
VB.NET文件合并這一操作方法,在文件操作中是一個(gè)比較常見(jiàn)的操作。大家可以跟隨本文給出的代碼示例,進(jìn)行一番實(shí)踐編寫(xiě),加深對(duì)此的印象。
VB.NET編程語(yǔ)言在文件的操作方面體現(xiàn)了非常大的作用。比如今天要為大家介紹的VB.NET文件合并,就可以應(yīng)用VB.NET來(lái)輕松的實(shí)現(xiàn)。大家就一起來(lái)具體的解讀這段代碼來(lái)對(duì)此進(jìn)行一個(gè)詳細(xì)的了解。
VB.NET文件合并代碼實(shí)現(xiàn)示例:
- 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文件合并的相關(guān)實(shí)現(xiàn)方法就為大家介紹到這里。
【編輯推薦】
責(zé)任編輯:曹凱
來(lái)源:
中國(guó)IT實(shí)驗(yàn)室