I am trying to send a directory listing over sockets but getting an error. Please help.
Example remote string being sent: The keyword, "directory" is cut out and only the directory path is fed into the userInput variable. The intent is to have the directory listing of both directories and files saved and sent back to the requestor.
Example string being sent: directoryc:usersnatedesktop
var input = socket.recvLine()
if input[0..8] == "directory":
let userInput = input[9..^1]
let filePaths = toSeq(walkDir(userInput, relative = true))
.mapIt(it.path)
socket.send(filePaths)
Error:
Error: type mismatch: got <Socket, seq[string]>
but expected one of:
proc send(socket: Socket; data: pointer; size: int): int
first type mismatch at position: 2
required type for data: pointer
but expression 'filePaths' is of type: seq[string]
proc send(socket: Socket; data: string; flags = {SafeDisconn})
first type mismatch at position: 2
required type for data: string
but expression 'filePaths' is of type: seq[string]
expression: send(socket, filePaths)
Hey, got it working. Thanks for making me think better....lol.
Here is what I was able to come up. Not the prettiest but its working.
if input[0..3] == "path":
var my_path = input[5..^1]
for entry in walkDir(my_path):
let the_path = entry.path
let path_to_send = $the_path
socket.send(path_to_send & "\n")
output:
path c:\users
c:\users\All Users
c:\users\Default
c:\users\Default User
c:\users\desktop.ini
c:\users\nater
c:\users\Public
Thanks again!