以下是我的代码:运行命令行是不正确的摇篮
task encodeFile(type: Exec) {
workingDir dirName
def files = file(dirName).listFiles()
files.each { File file ->
if (file.isFile()) {
println " *** $file.name *** "
def tmpName = "tmp$file.name"
println " === $tmpName"
commandLine "cmd", "/c native2ascii $file.name $tmpName"
commandLine "cmd", "/c del $file.name"
commandLine "cmd", "/c move $tmpName $file.name"
// commandLine "cmd", "/c move $file.name $tmpName"
println " === $file.name is moved"
println "----------------------------------"
// """executable "native2ascii" "$file.name" "$tmpName""""".execute()
}
}
}
我尝试编码所有本地化指定文件夹下的文件。但是当我运行上面的代码时,只有最后一个文件按预期更改。我打印了一些消息,并重复了所有文件。
有谁知道这里发生了什么?
是的,'最后一次迭代each'上'调用files'对象设置配置了和*胜* - 您可以更改为了验证它。 'native2ascii'能够同时处理多个文件吗? – Opal 2015-03-25 05:45:07