VB.Net实现文件合并的实例

前端之家收集整理的这篇文章主要介绍了VB.Net实现文件合并的实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB.NET实现文件合并的实例

Code:
  1. PrivateSubMergeFiles(ByValinputDirAsString,ByValinputMaskAsString,ByValoutputPathAsString)
  2. 'storefilesindatatablewiththeircreatedtimestosortbylater
  3. DimfilesAsNewDataTable
  4. files.Columns.Add("filepath",GetType(String))
  5. files.Columns.Add("creationtime",GetType(Date))
  6. 'findpartialfiles
  7. ForEachfAsStringInIO.Directory.GetFiles(inputDir,inputMask)
  8. files.Rows.Add(NewObject(){f,IO.File.GetCreationTime(f)})
  9. Next
  10. 'makesureoutputfiledoesnotexistbeforewriting
  11. IfIO.File.Exists(outputPath)Then
  12. IO.File.Delete(outputPath)
  13. EndIf
  14. 'loopthroughfileinorder,andappendcontentstooutputfile
  15. ForEachdrAsDataRowInfiles.Select("","creationtime")
  16. DimcontentsAsString=My.Computer.FileSystem.ReadAllText(CStr(dr("filepath")))
  17. My.Computer.FileSystem.WriteAllText(outputPath,contents,True)
  18. Next
  19. EndSub

猜你在找的VB相关文章