Last active
June 30, 2019 07:29
-
-
Save hiking93/7376870a5b576cf7023bedef7f8cdc6e to your computer and use it in GitHub Desktop.
Vuze VR Studio rendering loses original file creation time. Sync date of rendered files with raw files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.nio.file.Files | |
import java.nio.file.Files.getFileAttributeView | |
import java.nio.file.Paths | |
import java.nio.file.attribute.BasicFileAttributeView | |
import java.nio.file.attribute.FileTime | |
import java.text.SimpleDateFormat | |
val rootDir = File("/path/to/root") | |
val rawDir = File(rootDir, "Raw") | |
val renderedDir = File(rootDir, "Rendered") | |
fun main() { | |
val rawFiles = getFiles(rawDir) | |
val renderedFileNameRegex = "(HET_\\d+)_.+".toRegex() | |
renderedDir.listFiles()!!.filter { it.isFile }.forEach { renderedFile -> | |
println("Rendered file: ${renderedFile.absolutePath}") | |
val imageName = renderedFileNameRegex.matchEntire(renderedFile.name)?.groups?.get(1)?.value ?: run { | |
println("Can not resolve image name: ${renderedFile.name}.") | |
return@forEach | |
} | |
val rawFile = rawFiles.find { it.name.matches("$imageName\\..+".toRegex()) } ?: run { | |
println("Raw file not found: ${renderedFile.name}.") | |
return@forEach | |
} | |
println("Raw file: ${rawFile.absolutePath}") | |
val originalFileTime = renderedFile.getLastModifiedTime() | |
val targetFileTime = rawFile.getLastModifiedTime() | |
getFileAttributeView(renderedFile.toPath(), BasicFileAttributeView::class.java) | |
.setTimes(targetFileTime, null, targetFileTime) | |
println("${originalFileTime.toFormattedTime()} -> ${renderedFile.getLastModifiedTime().toFormattedTime()}") | |
println() | |
} | |
} | |
fun getFiles(dir: File): List<File> = dir.listFiles()!!.flatMap { if (it.isDirectory) getFiles(it) else listOf(it) } | |
fun File.getLastModifiedTime(): FileTime = | |
Files.getFileAttributeView( | |
Paths.get(absolutePath), | |
BasicFileAttributeView::class.java | |
).readAttributes().lastModifiedTime() | |
fun FileTime.toFormattedTime() = SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(toMillis())!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment