开发者

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

开发者 https://www.devze.com 2023-04-06 16:23 出处:网络
Does anyone know a tool that can add predefined text such as the following 4 lines: \"My disclaimer: For legal reasons -

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

精彩评论

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

关注公众号