Solaris groovy脚本 实现文件复制

阅读更多
#!/home/kate_sunrise/test_zsc/groovy-2.2.2/bin/groovy

class CopyFolder {

def copyFolder(def oldDir, def newDir) {
(new File(newDir)).mkdirs() // if not exit, create one
def file = new File(oldDir)
def listFile = file.listFiles()
def temp

for (f in listFile) {
temp = new File(oldDir + File.separator + f.name)

if (temp.isFile()) {
new File(newDir + File.separator + temp.name).withWriter {
writer ->
temp.eachLine {
line ->
writer.writeLine(line)
}
}
}
else if (temp.isDirectory()) {
copyFolder(oldDir + File.separator + temp.name, newDir + File.separator + temp.name)
}
}
}


public static void main(def args){
println 'Programme begin'
def copyFolder = new CopyFolder ()
copyFolder.copyFolder("/home/kate_sunrise/test_zsc/code/1", "/home/kate_sunrise/test_zsc/code/2")
println 'Programme end'
}
}

你可能感兴趣的:(Solaris,groovy)