windows 向现有源文件添加标题(版权)信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4436792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add header(copyright) information to existing source files
提问by jai
I want to add our company's copyright information to all of our EXISTING source code files.
我想将我们公司的版权信息添加到我们所有现有的源代码文件中。
The project is developed in Eclipse
. so, for new files I can modify the settings as suggested here. But for existing files, how am I supposed to do this. How can I modify hundreds of java files to add the copyright information. (And I'm unable to open the releng plugin mentioned in the above link.
该项目是在Eclipse
. 因此,对于新文件,我可以按照此处的建议修改设置。但是对于现有文件,我该怎么做。如何修改数百个java文件以添加版权信息。(而且我无法打开上面链接中提到的 releng 插件。
Any windows based text maniputaion scripting language will also help.
任何基于 Windows 的文本操作脚本语言也将有所帮助。
回答by TrueWill
回答by data
Correcting Konstantin's solution:
更正康斯坦丁的解决方案:
find . -name \*.java -exec sh -c "mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp" \;
Problem was that && is being interpreted by the shell directly instead of being passed to find. Escaping them is no solution either, as the find exec does not understand them. So just give the whole command to some shell.
问题是&& 被shell 直接解释而不是被传递给find。转义它们也不是解决方案,因为 find exec 不理解它们。所以只需将整个命令交给某个 shell。
回答by Suresh
回答by Konstantin
I would install CygWin (core + find) and do something of a kind
我会安装 CygWin(核心 + 查找)并做一些事情
find . -name *.java -exec mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp \;
find . -name *.java -exec mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp \;
回答by jargalan
I think you can use Eclipse replace command using Regular Expression.
我认为您可以使用正则表达式使用 Eclipse 替换命令。
Imagine that your copyright is something like:
想象一下,您的版权是这样的:
/* jQuery UI CSS Framework
* Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
*/
then
然后
1. Go to menu: Search -> File
2. in the Search dialog
2.1. check the "Regular Expression"
2.2. in the Containing text:
\A[^(\Q/*\E\s+jQuery.*)]
2.3 click the Replace
past your copyright
Explanation of regex:
正则表达式说明:
\A - Start of the file
\A - 文件的开头
\Q...\E - Here goes the regex keywords ( because / and * are keys in regex )
\Q...\E - 这是正则表达式关键字(因为 / 和 * 是正则表达式中的键)
\s+ - whitespaces
\s+ - 空格
[^(..)] - means except
[^(..)] - 表示除了