本文介绍了如何在gradle中删除一个空目录(或递归地包含所有内容的目录)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我无法弄清楚如何删除目录中的所有内容。 清理一个目录,我想删除其中的所有文件和目录:我想擦除里面的所有内容(文件和目录)。 我尝试过使用删除任务,但我无法弄清楚它也会删除目录而不仅仅是文件。 任务deleteGraphicsAssets(类型:删除){$ b $删除fileTree('src').include('** / *')} pre $ 任务deleteGraphicsAssets(类型:删除){删除fileTree('src').include(' /')} 。 任务deleteGraphicsAssets(类型:删除){删除fileTree('src').include('*')} $ p $ b p>编辑: 这很有效 - 但它看起来有点像破解。 def dirName =src删除dirName doLast { file(dirName).mkdirs( )} } 我正在寻找类似的东西: 任务删除GraphicsAssets(类型:删除){ deleteContentsOfDirectorysrc} 或 任务deleteGraphicsAssets(类型:删除){ delete {dir:src,keepRoot:true} 解决方案 删除 src 目录及其所有内容: 任务deleteGraphicsAssets(类型:删除){删除src} I can't figure out how to delete all contents of a directory.For cleaning out a directory, I want to remove all files and directories inside it: I want to wipe everything there is inside (files and directories).I tried this with the delete task, but I can't figure out to make it also remove directories and not just files. I've tried different ways to specify the directories, but nothing works.task deleteGraphicsAssets(type:Delete) { delete fileTree('src').include('**/*')}.task deleteGraphicsAssets(type:Delete) { delete fileTree('src').include('/')}.task deleteGraphicsAssets(type:Delete) { delete fileTree('src').include('*')}Any help appreciated!Edit:This works - yet it seems a bit like a hack.task deleteGraphicsAssets(type: Delete) { def dirName = "src" delete dirName doLast { file(dirName).mkdirs() }}I was looking for something like:task deleteGraphicsAssets(type: Delete) { deleteContentsOfDirectory "src"}or task deleteGraphicsAssets(type: Delete) { delete {dir : "src", keepRoot : true }} 解决方案 To delete the src directory and all its contents:task deleteGraphicsAssets(type: Delete) { delete "src"} 这篇关于如何在gradle中删除一个空目录(或递归地包含所有内容的目录)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 08:32