工具或 vbscript 将硬编码文本添加到多个文件的顶部?

发布于 2024-12-05 12:16:29 字数 228 浏览 3 评论 0原文

有谁知道一个工具可以添加预定义文本,例如以下 4 行:

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

到目录中的所有 .txt 文件:“C:/test/”

我见过附加函数,但它们只添加到底部,不确定添加到文件顶部的方法。

我的操作系统是Win XP。

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 append 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年里的时光 2024-12-12 12:16:29

SrcHead 是一个免费实用程序,可以调整多个源文件的标头。它是为 Windows 编写的,需要 .NET Framework 2.0 才能工作。

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.

一紙繁鸢 2024-12-12 12:16:29

还没有测试过这个,但它应该会让你走上正确的轨道。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文