Implemented 'cd' and 'ls' commands using Windows APIs.

This commit is contained in:
Jakob Friedl
2025-07-07 21:30:05 +02:00
parent 6a92a19b9e
commit ba7c8b6841
12 changed files with 290 additions and 21 deletions

View File

@@ -0,0 +1,27 @@
import os, strutils, base64, winim, strformat, sequtils
import ../types
proc taskCd*(task: Task): TaskResult =
let targetDirectory = task.args.join(" ").replace("\"", "").replace("'", "")
echo fmt"Changing current working directory to {targetDirectory}."
try:
# Get current working directory using GetCurrentDirectory
if SetCurrentDirectoryW(targetDirectory) == FALSE:
raise newException(OSError, fmt"Failed to change working directory ({GetLastError()}).")
return TaskResult(
task: task.id,
agent: task.agent,
data: encode(""),
status: Completed
)
except CatchableError as err:
return TaskResult(
task: task.id,
agent: task.agent,
data: encode(fmt"An error occured: {err.msg}" & "\n"),
status: Failed
)