# C++ - Stdlib.h - system() (newbie question)



## Romulan03 (May 24, 2003)

Hi,

Just wondering if it is possible to be more specific with the system() function and pass a variable to it, containing a directory. 

For example, using the 'cd' command in system(), is there any way to pass a variable containing the directory to change to?

Thanks


----------



## IMM (Feb 1, 2002)

The command is simply passed as a string.
For example:

```
#include &lt;stdlib.h&gt;;
void main( void )
{
   system( "dir c:\\windows\\system");
}
```
You may find that with the cd command you will have some difficulty with respect to what you expect as a result and figuring out what is running as the 'command interpreter'.
What exactly are u trying to do?


----------



## Romulan03 (May 24, 2003)

I know that part, what I need to do is:

#include <stdlib.h>

int main() {

// cin >> variable containing dir

system("cd variabledir");

}

The directory to be moved to needs to be variable and not a single directory.


----------



## Shadow2531 (Apr 30, 2001)

You can try the attached file. It works using the dir command to list the directory content, but also changes to the directory you input.

You have to use the 8 character dos folder names though.

I am sure there are a lot better ways to do it.

Hint*


----------



## Romulan03 (May 24, 2003)

Thanks for your help.


----------

