开发者

tool or vbscript to add hardcoded text to top of multiple files?

Does anyone know a tool that can add predefined text such as the following 4 lines:

"My disclaimer:
For legal reasons -
1. Don't blah...
2. You must..."

to all .txt files in a directory: "C:/test/"

I have seen ap开发者_如何学运维pend functions but they only add to the bottom, not sure of a method for adding to the top of the file.

My OS is Win XP.


SrcHead is a free utility that can adjust the header of multiple sourcefiles. It is written for Windows and needs the .NET Framework 2.0 to work.


Haven't tested this, but it should put you on the right track.

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

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

        Set txs = fil.OpenAsTextStream(1) ' 1 = for reading
        content = txs.ReadAll
        txs.Close

        Set txs = fil.OpenAsTextStream(2) ' 2 = for writing
        txs.Write "MyDisclaimer:" & vbCrLf & "stuff" & content
        txs.Close

    End If    
Next
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜