Groovy脚本替换多文件中的文本

2015-12-14 0 209
Groovy脚本替换多文件中的文本
def currentDir = new File("d:/bakup");

def backupFile;
def fileText;

//Replace the contents of the list below with the 
//extensions to search for
def exts = [".htm"]

//Replace the value of srcExp to a String or regular expression
//to search for.
def srcExp = "<p align=\"left\"><a href=\"#1\">"

//Replace the value of replaceText with the value new value to 
//replace srcExp
def replaceText =new File("poem os china.txt").text

currentDir.eachFileRecurse(
  {file ->
    for (ext in exts){
      if (file.name.endsWith(ext)) {
        fileText = file.text;
       // backupFile = new File(file.path + ".bak");
        //backupFile.write(fileText);
        fileText = fileText.replaceAll(srcExp, replaceText)
        file.write(fileText);
      }
    }
  }
)

遇见资源网 groovy Groovy脚本替换多文件中的文本 http://www.ox520.com/13680.html

上一篇:

已经没有上一篇了!

下一篇:

已经没有下一篇了!

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务