Listing Files in directory and subdirectories

0 votes
asked Sep 11, 2014 by alib28 (130 points)
edited Sep 12, 2014

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
answered Sep 12, 2014 by Lukas Pokorny (88,550 points)
edited Sep 12, 2014

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"

...