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

com.xml.guard.utils.FileExt.kt Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.xml.guard.utils

import java.io.File

val File.isJava: Boolean
    get() = this.name.endsWith(".java")

val File.isKt: Boolean
    get() = this.name.endsWith(".kt")

val File.isAidl: Boolean
    get() = this.name.endsWith(".aidl")

val File.isXml: Boolean
    get() = this.name.endsWith(".xml")

val File.isAndroidManifest: Boolean
    get() = this.name == "AndroidManifest.xml"

fun deleteEmptyDirectories(
    directory: File,
    fileFilter: (directory: File) -> Boolean = { true }
) {
    if (!directory.exists() || !directory.isDirectory) {
        return
    }
    val files = directory.listFiles()
    if (files?.isNotEmpty() == true) {
        for (file in files) {
            if (file.isDirectory) {
                deleteEmptyDirectories(file, fileFilter)
            }
        }
    }
    if (directory.listFiles()?.isEmpty() == true
        && fileFilter.invoke(directory)
    ) {
        directory.delete()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy