Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打开并保存(覆盖)多个xml文件_Xml_Batch File_Vbscript - Fatal编程技术网

打开并保存(覆盖)多个xml文件

打开并保存(覆盖)多个xml文件,xml,batch-file,vbscript,Xml,Batch File,Vbscript,我需要一个脚本来打开文件夹中的所有xml文件,并立即保存(覆盖)xml文件。原因是XML文件的编码,我需要用UTF-8保存,重新保存是我找到的最简单的方法 我怎样才能做到这一点 `@if (@this==@isBatch) @then @echo off cscript //nologo //e:jscript "%~f0" ^ /input:"input_file.xml" ^ /output:"output_file.xml" ^ /from

我需要一个脚本来打开文件夹中的所有xml文件,并立即保存(覆盖)xml文件。原因是XML文件的编码,我需要用UTF-8保存,重新保存是我找到的最简单的方法

我怎样才能做到这一点

`@if (@this==@isBatch) @then
@echo off

cscript //nologo //e:jscript "%~f0" ^
        /input:"input_file.xml" ^
        /output:"output_file.xml" ^
        /from:"x-ansi" ^
        /to:"utf-8"

exit /b

@end
var adTypeText = 2;
var adSaveCreateOverWrite = 2;

var inputFile = WScript.Arguments.Named.Item('input');
var outputFile = WScript.Arguments.Named.Item('output');

var from = WScript.Arguments.Named.Item('from');
var to = WScript.Arguments.Named.Item('to');

var inputStream  = WScript.CreateObject('adodb.stream');
with (inputStream){
    Type = adTypeText;
    Charset = from;
    Open();
    LoadFromFile( inputFile );
}

var outputStream = WScript.CreateObject('adodb.stream')
with (outputStream){
    Type = adTypeText;
    Charset = to;
    Open();
    WriteText( inputStream.ReadText );
    SaveToFile( outputFile, adSaveCreateOverWrite );
}

inputStream.Close()
outputStream.Close()`

您的代码过于复杂和复杂

您的主要问题很简单,正如本程序所示,计算文件夹中文档的字数

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFolder("c:\")
For Each thing in f.files
    If LCase(Right(thing.path, 3)) = "doc" Then
        Set doc = GetObject(thing.path)
                For each wd in doc.words
                    If wd = "cat" then Counter = Counter + 1
                Next
    Doc.close
    Set Doc = Nothing
    End If
Next
MsgBox Counter

在循环中使用stream
Charset
属性。

有关UltraEdit脚本解决方案,请查看