我有这个代码,它将文件夹中每个文本文件的名称和内容组合成一个字符串
Dim dir As New DirectoryInfo("D:\txtfiles\")
Dim fiArr As FileInfo() = dir.GetFiles()
Dim fri As FileInfo
For Each fri In fiArr
Dim gg As Integer = 300000
If gg > fri.Length Then
File.AppendAllText("1.txt", "|*|" & fri.Name & "|*|", Encoding.UTF8)
File.AppendAllText("1.txt", File.ReadAllText(fri.FullName), Encoding.UTF8) 'The text file will be created if it does not already exist
End If
Next fri
现在我需要再次拆分它们,用它的名称和内容保存每个文本文件 拆分器必须是“| * |”
答案 0 :(得分:2)
Private Sub CreateFiles(dest As String, s As String)
Dim a = s.Split("|*|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
For i As Integer = 0 To a.Count() - 2 Step 2
File.WriteAllText(dest & a(i), a(i + 1))
Next
End Sub
dest
是您希望将文件保存到的目录
s
是您的代码创建的文件的内容
请注意!别忘了在字符串dest