commit 09/09/2025
This commit is contained in:
@@ -12,6 +12,7 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.function.Consumer
|
||||
import kotlin.io.path.name
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
@@ -30,6 +31,34 @@ class Somecodes {
|
||||
const val GB_threshold = MB_threshold * 1024.0
|
||||
const val TB_threshold = GB_threshold * 1024.0
|
||||
|
||||
/**
|
||||
* List all audio files (.mp3 and .wav) in the specified directory and its subdirectories.
|
||||
* Only files larger than 1KB are included.
|
||||
* @param dir The directory to search in (default is the current working directory).
|
||||
* @return A list of absolute paths to the audio files found.
|
||||
*/
|
||||
fun ListAudioFiles(dir: String = current_directory) : List<String>{
|
||||
return try{
|
||||
// find all files that ends with .mp3 or .wav
|
||||
// and find them recursively
|
||||
val p = Path.of(dir)
|
||||
if (Files.exists(p) && Files.isDirectory(p)){
|
||||
Files.walk(p)
|
||||
// cari file regular saja
|
||||
.filter { Files.isRegularFile(it)}
|
||||
// size lebih dari 1KB
|
||||
.filter { Files.size(it) > 1024}
|
||||
// extension .mp3 atau .wav
|
||||
.filter { it.name.endsWith(".mp3",true) || it.name.endsWith(".wav",true) }
|
||||
.map { it.toAbsolutePath().toString() }
|
||||
.toList()
|
||||
} else throw Exception()
|
||||
|
||||
} catch (_ : Exception){
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a size in bytes to a human-readable format.
|
||||
* @param size Size in bytes.
|
||||
|
||||
Reference in New Issue
Block a user