views:

117

answers:

1

Hello, how can I delete every n-th (4000th) char (space character) in a file (.txt or .sql) best via batch or vbs?

Thanks in advance!

+3  A: 

You need some VBScript, you can't do this with a batch file. So something like this will do it for you

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

Hope this helps :)

Binary Worrier
That's it :) For the first loop I had to add an offset (since first intervall is about 4023 chars) and now it's working perfect. Thanks a lot!
seansilver
I still think it is possible with a batch. Although it might depend on what characters can be expected in the files. I might try crafting a batch solution later :)
Joey
@Johannes Rössel: Go for it! I'd be interested to see how this could be achieved :)
Binary Worrier