Created
November 22, 2023 15:47
-
-
Save shakir915/49bedb22bbffe82aca885f4503c5abe0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.io.IOException | |
import java.util.concurrent.TimeUnit | |
fun travers(file: File) { | |
file.listFiles().forEach { | |
if (it.isDirectory) { | |
travers(it) | |
} else { | |
var command = "afconvert \"${it.path}\" \"${it.path.split(".").toMutableList().apply { removeLast() }.joinToString("")}.caf\" -d ima4 -f caff -v" | |
println(command) | |
println(" out "+command.runCommand2(it.parentFile)) | |
} | |
} | |
} | |
travers(File("/Users/shakir/Downloads/masjid_sounds")) | |
fun String.runCommand(workingDir: File) { | |
ProcessBuilder(*split(" ").toTypedArray()) | |
.directory(workingDir) | |
.redirectOutput(ProcessBuilder.Redirect.INHERIT) | |
.redirectError(ProcessBuilder.Redirect.INHERIT) | |
.start() | |
.waitFor(60, TimeUnit.MINUTES) | |
} | |
fun String.runCommand2(workingDir: File): String? { | |
try { | |
val parts = this.split("\\s".toRegex()) | |
val proc = ProcessBuilder(*parts.toTypedArray()) | |
.directory(workingDir) | |
.redirectOutput(ProcessBuilder.Redirect.PIPE) | |
.redirectError(ProcessBuilder.Redirect.PIPE) | |
.start() | |
proc.waitFor(60, TimeUnit.MINUTES) | |
return proc.inputStream.bufferedReader().readText() | |
} catch (e: IOException) { | |
e.printStackTrace() | |
return null | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment