2017-09-18 77 views
0

我試圖刪除文件集,因爲我是在很多examples搖籃刪除文件集

task deleteApkFiles(type: Delete) << { 
    println("-------------------------------------") 
    println("---------------DELETE---------------") 
    println("-------------------------------------") 
    def files = fileTree(dir: '.', include: '**/*.apk').files 
    delete fileTree(dir: '.', include: '**/*.apk') 
    println(files) 

} 

打印的只顯示我想delte

[app-minAPI16-prod-release.apk, app-minAPI16-prod-release.apk, app-minAPI16-beta-debug.apk] 

我的文件,但delete不delets他們

回答

0

管理在foreach循環來刪除文件

def files = fileTree(dir: '.', include: '**/*.apk').files 
files.each {File f -> delete f} 
+1

這將構建的gradle,這可能是一件壞事做 –

1

剛刪除<<

它會工作。我不知道爲什麼=)

task deleteApkFiles(type: Delete) { 
    println("-------------------------------------") 
    println("---------------DELETE---------------") 
    println("-------------------------------------") 
    delete fileTree(dir: '.', include: '**/*.apk') 
} 
+2

它的工作原理是因爲'的配置中刪除文件<<'增加了任務和配置'行動刪除「已經太遲了。 – Opal

+0

'<<'已棄用,將在5.0中刪除。 – mkobit

+1

它的作品,因爲這是[你應該這樣做](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Delete.html) –