试图弄清楚如何修改下面的代码以添加到文件末尾恰好有一个额外的 CRLF 的文本文件中。根据我放置 CHR(10) 的位置,我会得到令人困惑的结果。任何想法如何剥离 CRLF 或删除空行?我最终需要没有额外的 CRLF !!!
'如果 RandomCSV 文件不是 20 的倍数,此脚本将添加行。'如果文件已经是 20 的倍数,则不会发生任何事情。
dim filesys, readfile, contents, lines, remainder, LinesToAdd, StaticLine, Appendfile, Count
dim field1, field2, field3, field4
set filesys = CreateObject("Scripting.FileSystemObject")
Set readfile = filesys.OpenTextFile("C:\RandomCSV.txt", 1, false)
contents = readfile.ReadAll
Lines = readfile.line
readfile.close
MsgBox "The file contains this many lines " & Lines
remainder = lines mod 20
LinesToAdd = (20 - remainder)
MsgBox "Adding this many lines " & LinesToAdd
If LinesToAdd <> 20 then
Set Appendfile = filesys.OpenTextFile("C:\RandomCSV.txt", 8, false)
For Count = 1 to LinesToAdd
Appendfile.write Chr(34) & "Field1" & Chr(34) & Chr(44) & Chr(34) & "Field2" & Chr(34) & Chr(44) & Chr(34) & "Field3" & Chr(34) & Chr(44) & Chr(34) & "Field4" & Chr(10)
Next
appendfile.close
End If