将行插入非文本文件
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
dxfFile$
不是有效的 VBscript 变量名;使用 dxfFile
、file
或 dfxPath
(一致)
FileExists
是FileSystemObject的一个方法;你需要打电话给 fso.FileExists
dxfFile
、dfxPath
、ForAppending
均未定义
- 使用 undefined/empty first/filespec 参数调用
.OpenTextFile
会引发错误 5 - 过程调用或参数无效
- 您不能通过附加行来插入行;修改文件 'in the middle' 在 VBScript 中特别笨拙;将整个文件加载到内存中,编辑,写回可能对你有用
- .DFX 文件以 ASCII 或二进制格式出现;如果是后者,则不能使用 FileSystemObject(参见 ADODB.Stream)
我正在尝试将行插入非文本文件的中间(文件的扩展名是 "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
dxfFile$
不是有效的 VBscript 变量名;使用dxfFile
、file
或dfxPath
(一致)FileExists
是FileSystemObject的一个方法;你需要打电话给fso.FileExists
dxfFile
、dfxPath
、ForAppending
均未定义- 使用 undefined/empty first/filespec 参数调用
.OpenTextFile
会引发错误 5 - 过程调用或参数无效 - 您不能通过附加行来插入行;修改文件 'in the middle' 在 VBScript 中特别笨拙;将整个文件加载到内存中,编辑,写回可能对你有用
- .DFX 文件以 ASCII 或二进制格式出现;如果是后者,则不能使用 FileSystemObject(参见 ADODB.Stream)