main.com.xml.guard.utils.FileExt.kt Maven / Gradle / Ivy
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()
}
}