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

时间:2023-01-14 10:59:33

I need a Script to open all xml files in a folder and instantly save (OverWrite) a Xml File. The reason is the encoding of the XML file, I need to save in UTF-8 and resaving is the easiest way that I found.

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

How can I achieve this?

我怎样才能做到这一点?

`@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()`

1 个解决方案

#1


0  

Your code is far too complex and convoluted.

你的代码太复杂而且复杂。

Your principal question is simple as this progam to count words in documents in a folder shows.

你的主要问题很简单,因为这个程序可以计算文件夹中文档中的单词。

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

For you use the stream Charset property in the loop.

对于您在循环中使用流Charset属性。

#1


0  

Your code is far too complex and convoluted.

你的代码太复杂而且复杂。

Your principal question is simple as this progam to count words in documents in a folder shows.

你的主要问题很简单,因为这个程序可以计算文件夹中文档中的单词。

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

For you use the stream Charset property in the loop.

对于您在循环中使用流Charset属性。