如何删除文件中的每个第n个字符(通过批处理或vbs)?

时间:2009-07-30 09:16:47

标签: batch-file vbscript character

如何通过批处理或vbs删除文件(.txt或.sql)中的每个第n个(第4000个)字符(空格字符)?

1 个答案:

答案 0 :(得分:4)

您需要一些VBScript,不能使用批处理文件。 所以像这样的东西会为你做这件事

option Explicit

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim fso 

Dim inFile 
Dim outFile 
Dim buffer 

set fso = CreateObject("Scripting.FileSystemObject")

Set inFile = fso.OpenTextFile("C:\testIn.txt", ForReading)
Set outFile = fso.OpenTextFile("C:\testOut.txt", ForWriting, True)

Do While Not inFile.AtEndOfStream
    buffer = inFile.Read(3999)
    outFile.Write buffer
    If Not inFile.AtEndOfStream Then
        inFile.Read (1)
    End If
Loop

inFile.Close
outFile.Close

希望这会有所帮助:)