VB.NET实现文件合并的实例
- PrivateSubMergeFiles(ByValinputDirAsString,ByValinputMaskAsString,ByValoutputPathAsString)
- 'storefilesindatatablewiththeircreatedtimestosortbylater
- DimfilesAsNewDataTable
- files.Columns.Add("filepath",GetType(String))
- files.Columns.Add("creationtime",GetType(Date))
- 'findpartialfiles
- ForEachfAsStringInIO.Directory.GetFiles(inputDir,inputMask)
- files.Rows.Add(NewObject(){f,IO.File.GetCreationTime(f)})
- Next
- 'makesureoutputfiledoesnotexistbeforewriting
- IfIO.File.Exists(outputPath)Then
- IO.File.Delete(outputPath)
- EndIf
- 'loopthroughfileinorder,andappendcontentstooutputfile
- ForEachdrAsDataRowInfiles.Select("","creationtime")
- DimcontentsAsString=My.Computer.FileSystem.ReadAllText(CStr(dr("filepath")))
- My.Computer.FileSystem.WriteAllText(outputPath,contents,True)
- Next
- EndSub