-
Notifications
You must be signed in to change notification settings - Fork 0
/
WPSClean.main.kts
36 lines (34 loc) · 1.01 KB
/
WPSClean.main.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.File
import java.lang.module.ModuleDescriptor
val namesFile: MutableMap<String, MutableMap<ModuleDescriptor.Version, File>> = HashMap()
File(
System.getenv("APPDATA"), """\kingsoft\wps\addons\pool\win-i386"""
).listFiles()?.forEach { file ->
val fileName = file.name
val split = fileName.split("_")
val name = if (split.size == 2) {
split[0]
} else {
fileName.substringBefore(split[split.size - 1])
}
val version = ModuleDescriptor.Version.parse(split.last())
namesFile.getOrPut(name, ::HashMap)[version] = file
}
namesFile.values.filter { it.size > 1 }.forEach { versionFileMap ->
val maxVersion = versionFileMap.keys.max()
versionFileMap.remove(maxVersion)
versionFileMap.values.forEach { file ->
println("delete: $file")
deleteDir(file)
}
}
private fun deleteDir(dir: File) {
if (dir.isFile) {
dir.delete()
} else {
for (file in dir.listFiles()) {
deleteDir(file)
}
dir.delete()
}
}