注意: repository的路径需根据自己的配置更改
Scala代码:
package system.util
import java.io.File
/**
* 删除maven目录下的.lastUpdated文件以及所在文件夹
*
* @author 王大仙儿
* @date 2019/12/25 15:37
*/
object CleanMavenFile {
def main(args: Array[String]): Unit = {
val cleanFileBySuffix = new CleanMavenFile()
cleanFileBySuffix.statisticsDirectorys("C:\\Users\\Administrator\\.m2\\repository")
cleanFileBySuffix.deleteDirectorys()
}
}
import scala.collection.mutable
class CleanMavenFile {
val suffix = ".lastUpdated"
val directorys = mutable.Set[String]()
def statisticsDirectorys(path: String) {
new File(path).listFiles().foreach(file => {
if (file.isDirectory) {
statisticsDirectorys(file.getPath)
} else {
if (file.getName.contains(suffix)) {
directorys.add(file.getParent)
}
}
})
}
def deleteDirectorys(){
var directory: File = null
directorys.foreach(line => {
directory = new File(line)
if (directory.exists()) {
directory.listFiles().foreach(file => {
if (file.delete()) {
println(s"删除文件: ${file.getPath} 成功")
} else {
println(s"删除文件: ${file.getPath} 失败")
}
})
if (directory.delete()) {
println(s"删除文件夹: ${directory.getPath} 成功")
} else {
println(s"删除文件夹: ${directory.getPath} 失败")
}
}
})
}
}
🐞标题:实用代码:清理maven下载失败的依赖(.lastUpdated文件以及所在文件夹)
👽作者:ruige
🐾地址:https://jjdhhc.com/articles/2020/11/07/1604720330378.html
🙏感恩:谢谢您的打赏与支持!中间图片是我的微信公众号,扫码关注哦!