All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jchanghong.utils.file.FileHelper.kt Maven / Gradle / Ivy

The newest version!
package com.jchanghong.utils.file

import com.jchanghong.utils.log.LogHelper.minfo
import java.io.File

/**
 *
 * @author : jiangchanghong
 *
 * @version : 2020-01-08 16:46
 **/
object FileHelper {
    private fun File.myDelete(): Unit {
        if (this.isDirectory) return
        val name = this.name
        if (name.endsWith(".lastUpdated ") || name.endsWith("_remote.repositories")) {
            this.delete()
            minfo(this.absolutePath.toString() + "已删除")
        }
    }

    @JvmOverloads
            /**删除文件   .lastUpdated _remote.repositories */
    fun removeMavenLastAndRemoteFiles(path: String, group: String = ""): Unit {
        var parent = File(path)
        if (!parent.exists() || parent.isFile) {
            error(path + "目录不存在")
        }
        if (group.isNotEmpty()) {
            parent = File(parent, group.split(".").joinToString(separator = "/"))
            if (!parent.exists() || parent.isFile) {
                error(path + "目录不存在")
            }
        }
        parent.walkTopDown().forEach { it.myDelete() }
    }
}


fun main() {
//    .lastUpdated _remote.repositories
    FileHelper.removeMavenLastAndRemoteFiles(
        """D:\mavendir""",
        "org.sonatype.plugins"
    )

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy