0 votes
by (130 points)
edited

I am trying to list all files inside a certain directory and its sub-directories, I used the following command:

string command = "dir /root/dirname /a-d /b /s"; shell.SendCommand(command);

but it's giving an error: cannot access /a-d: No such file or directory cannot access /b: No such file or directory cannot access /s: No such file or directory

What is wrong with my command?

1 Answer

+1 vote
by (148k points)
edited

It looks like you are trying to send a Windows prompt dir command to a Unix server. Although many Unix systems understand the dir command, its arguments are completely different and it doesn't even support file-only listings.

To list all files inside a certain directory and its sub-directories on Linux or other Unix-like OS, try using the find command:

find /home/lukasp -type f -printf "%p\n"

...