将行插入非文本文件

Inserting Lines into a Non-Text File

我正在尝试将行插入非文本文件的中间(文件的扩展名是 "dxf")。我正在使用 vbscript 来执行此操作。

到处看,我都遇到了FileSystemObject.OpenTextFile。但是,当我尝试在 dxf 文件上使用它时,它会导致错误:异常 80070057(我相信这是一个无效文件)。

这是我的代码:

Dim file
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

If fileexists(dxfFile$) Then
    Set file = fso.OpenTextFile(dxfPath, ForAppending, True)

    file.WriteLine("<PORTLIST TESTING>ASDFLKJ")
    file.Close
End If
  1. dxfFile$ 不是有效的 VBscript 变量名;使用 dxfFilefiledfxPath(一致)
  2. FileExists是FileSystemObject的一个方法;你需要打电话给 fso.FileExists
  3. dxfFiledfxPathForAppending 均未定义
  4. 使用 undefined/empty first/filespec 参数调用 .OpenTextFile 会引发错误 5 - 过程调用或参数无效
  5. 您不能通过附加行来插入行;修改文件 'in the middle' 在 VBScript 中特别笨拙;将整个文件加载到内存中,编辑,写回可能对你有用
  6. .DFX 文件以 ASCII 或二进制格式出现;如果是后者,则不能使用 FileSystemObject(参见 ADODB.Stream)