Hackers...do you have a better way to write this p...
# codereview
x
Hackers...do you have a better way to write this piece of code?
Copy code
import org.jetbrains.kotlin.com.intellij.util.TimeoutUtil

val formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")
val regex = Regex("^V\\d+__.*\\.js\$")
File("src/main/resources/db/migration").walk()
    .filterNot { it.isDirectory or it.name.matches(regex) }
    .forEach {
      val timestamp = ZonedDateTime.now(ZoneOffset.UTC).format(formatter)
      it.renameTo(File("${it.parent}${File.separatorChar}V${timestamp}__${it.name}"))
      TimeoutUtil.sleep(100) // Wait for a moment to avoid prefix conflicts when renaming multiple files in a batch
    }
s
vadimvera: is this just a script you occasionally run? or build script? If so, it’s probobly fine
x
Yeah, I use to prefix the "migration" files in order to execute then=m and make them "unique" in the Gradle build