开发者

tool or vbscript to delete first x lines from multiple files?

开发者 https://www.devze.com 2023-04-05 22:09 出处:网络
I\'ve fiddled a bit with wingrep but doesn\'t seem to support this. H开发者_StackOverflow中文版as anyone had any luck with say deleting the first 7 lines of text from all .txt files in directory \"C:

I've fiddled a bit with wingrep but doesn't seem to support this.

H开发者_StackOverflow中文版as anyone had any luck with say deleting the first 7 lines of text from all .txt files in directory "C:\my_direc\"?

I'm using Win XP.


Here's a VBScript solution. Haven't tested it, but it should at least put you on the right track.

Dim FSO, txs, fld, fil, content, nLinesToSkip, i
Set FSO = CreateObject("Scripting.FileSystemObject")

nLinesToSkip = 7

fld = FSO.GetFolder("C:\test\")
For Each fil In fld
    If Right(fil.Name, 3) = "txt" Then

        Set txs = fil.OpenAsTextStream(1) ' 1 = for reading
        For i = 1 To nLinesToSkip
            txs.SkipLine
        Next i
        content = txs.ReadAll
        txs.Close

        Set txs = fil.OpenAsTextStream(2) ' 2 = for writing
        txs.Write content
        txs.Close

    End If
Next fil


You can try Delete Lines tool

0

精彩评论

暂无评论...
验证码 换一张
取 消