5

我有以下代码..我在此语句 txsOutput.Writeline txsInput1.ReadAll 处收到无效调用或过程 ..组合文件是一个文本文件,其中包含一些采用这种格式

名称 test.css。

有人可以告诉我脚本有什么问题吗?

Dim strInputPath1
Dim txsInput1,txsOutput
Dim FSO

Dim Filename


Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = "C:\txt3.txt"
Set txsOutput = FSO.CreateTextFile(strOutputPath)

Set re = New RegExp
re.Pattern = "\s+"
re.Global  = True

Set f = FSO.OpenTextFile("C:\combination.txt")
Do Until f.AtEndOfStream
  tokens = Split(Trim(re.Replace(f.ReadLine, " ")))
  extension = Split(tokens(0),".")
  strInputPath1 =  "C:\inetpub\wwwroot\data\p\" & tokens(1) & "\" & extension(1) & "\" & tokens(0) 

Loop
f.Close

WScript.Echo strInputPath1

Set txsInput1 = FSO.OpenTextFile(strInputPath1, 1)
txsOutput.Writeline txsInput1.ReadAll

txsInput1.Close
txsOutput.Close
4

2 回答 2

10

调用 TextStream.WriteLine 时的错误 5 通常是由于尝试写入 TextStream 无法编码的数据引起的:

尝试将“U+1F00 ἀ e1 bc 80 GREEK SMALL LETTER ALPHA WITH PSILI”写入使用“ASCII”编码打开的流:

>> Set f = goFS.CreateTextFile(".\tmp.txt")
>> f.WriteLine "AÄ"
>>  --- no news here means: written ---
>> f.WriteLine ChrW(&H1F00)
>>
Error Number:       5
Error Description:  Invalid procedure call or argument

为了证明这一点:

>> f.close
>> Set f = goFS.CreateTextFile(".\tmp.txt", True, True) ' overwrite, unicode
>> f.WriteLine ChrW(&H1F00)
>>
>> --- no news are good news --

由于数据源 (.ReadAll()) 似乎来自 WWW,它很可能包含非 ASCII/ANSI 文本。但请注意,如果输入是 UTF-8 被 ASCII 文本流上的 .ReadAll() 吞并,则仅打开 Unicode (=UTF-16) 的输出文件将无济于事。

于 2013-06-13T18:57:44.567 回答
0

如果没有实际看到该特定输入文件,我们就无法告诉您更多信息。但是,您可以通过替换来隔离错误的来源:

txsOutput.Writeline txsInput1.ReadAll

像这样:

On Error Resume Next
Do Until txsInput1.AtEndOfStream
  line = txsInput1.ReadLine
  If Err Then
    WScript.Echo "Operation:   Read" & vbNewLine _
      "Error:       " & Err.Number & vbNewLine _
      "Description: " & Err.Description & vbNewLine _
      "Line:        " & txsInput1.Line
    WScript.Echo "Text:        " & line
  End If
  Err.Clear

  txsOutput.WriteLine line
  If Err Then
    WScript.Echo "Operation:   Write" & vbNewLine _
      "Error:       " & Err.Number & vbNewLine _
      "Description: " & Err.Description & vbNewLine _
      "Line:        " & txsInput1.Line
    WScript.Echo "Text:        " & line
  End If
  Err.Clear
Loop
On Error Goto 0

也可以选择使用十六进制编辑器检查输入文件。

于 2013-06-14T17:02:07.947 回答