ksmplayedsongs/ksmplayedsongs.nim

27 lines
1.0 KiB
Nim

import os
echo("Input KSM directory")
let mainDir: string = readLine(stdin)
echo("If your ingame player name is not 'PLAYER' enter it now (otherwise press enter)")
let playerName: string = readLine(stdin)
let userDir: string = mainDir & DirSep & "score" & DirSep & (if len(playerName) > 0: playerName else: "PLAYER")
echo("Enter the name of the 'folder' to create (or just leave empty for 'Played')")
let dirName: string = readLine(stdin)
let outFileName: string = mainDir & DirSep & "songs" & DirSep & (if len(dirName) > 0: dirName & ".fav" else: "Played.fav")
var f: File
if open(f, outFileName, fmWrite):
try:
for kind, path in walkDir(userDir, true):
if kind == pcDir:
let fullPath = userDir & DirSep & path
for k2, p2 in walkDir(fullPath, true):
if k2 == pcDir:
f.write(path & "\\" & p2)
# KSM can only read Windows style line endings
f.write('\r')
f.write('\n')
finally:
close(f)
else:
quit("Error writing to file: " & outFileName)