溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

VB.NET中怎么對文件進行合并

發(fā)布時間:2021-07-22 15:01:49 來源:億速云 閱讀:348 作者:Leah 欄目:編程語言

本篇文章給大家分享的是有關VB.NET中怎么對文件進行合并,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

VB.NET文件合并代碼實現(xiàn)示例:

  1. Private Sub MergeFiles(ByVal 
    inputDir As String, ByVal 
    inputMask As String, ByVal 
    outputPath As String)  

  2. 'store files in datatable 
    with their created times 
    to sort by later  

  3. Dim files As New DataTable  

  4. files.Columns.Add("filepath",
     GetType(String))  

  5. files.Columns.Add("creationtime",
     GetType(Date))  

  6. 'find partial files  

  7. For Each f As String In IO.
    Directory.GetFiles(inputDir, inputMask)  

  8. files.Rows.Add(New Object() 
    {f, IO.File.GetCreationTime(f)})  

  9. Next  

  10. 'make sure output file does
     not exist before writing  

  11. If IO.File.Exists(outputPath) Then  

  12. IO.File.Delete(outputPath)  

  13. End If  

  14. 'loop through file in order, 
    and append contents to output file  

  15. For Each dr As DataRow In 
    files.Select("", "creationtime")  

  16. Dim contents As String = 
    My.Computer.FileSystem.ReadAllText
    (CStr(dr("filepath")))  

  17. My.Computer.FileSystem.WriteAllText
    (outputPath, contents, True)  

  18. Next  

  19. End Su 

以上就是VB.NET中怎么對文件進行合并,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI