Skip to content

Instantly share code, notes, and snippets.

@eboudrant
Created October 25, 2022 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eboudrant/3735d050ab5984ba147a9ad4a75c2966 to your computer and use it in GitHub Desktop.
Save eboudrant/3735d050ab5984ba147a9ad4a75c2966 to your computer and use it in GitHub Desktop.
Re-order GoPro files in alphabetical order (renaming)
// Re-order GoPro files in alphabetical order (fine rename)
// Probably does not cover all use cases.
// more info about GoPro naming can be found here https://community.gopro.com/s/article/GoPro-Camera-File-Naming-Convention?language=en_US
import java.io.File
fun main(args: Array<String>) {
val dir = File("PATH_TO_DIR_CONTAINS_MP4_FILES")
dir.listFiles { dir, name ->
val part1 = name.substring(0, 4)
val part2 = name.substring(4, name.lastIndexOf("."))
if (part1.startsWith("GX") || part1.startsWith("GH")) {
val index = part1.substring(2, 4)
val newName = "VIDEO_${part2}_$index.MP4"
println("$dir/$newName")
File(dir, name).renameTo(File(dir, newName))
}
true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment