Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm designing a little software to use at home and I ran into a problem.

The server side needs to run cd to change the current directory and also ls to get the list of files and directories in the current directory.

The point is, I have absolutely no idea how to do it.

Can anyone help me out please?
Posted

Running the cd command with system() or some similar method won't change the current directory of the calling process. You should use the chdir()[^]/opendir()[^]/readdir()[^]/... functions or the boost::filesystem[^] library instead of external programs.
 
Share this answer
 
Haven't programmed in Linux in a while, but you should be able to use the C system() function. See http://www.opengroup.org/onlinepubs/000095399/functions/system.html[^]

The simplest way to parse the output of an ls command is to redirect output to a text file, and then parse that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900