Robbie said:
CLI or GUI?
If GUI, read your Win32 API manual; that's waaaaaaaaaay off-topic here.
If CLI, the C standard library function "system" (in <stdlib.h> )
would work:
system("CD \\sprat\\blat");
system("galumph");
On solaris and linux the system will spawn another process, do the cd,
then kill the process. your current pwd will still be the same.
To use system you would have to
system("cd /my_dir; do some work");
This unsures that all work is done in the spawned process.
THis is not just a c++ situation, it's any language, compiled or
interpreted.
ex:
in csh
is different from
`cd /my_dir`
echo pwd
cd /my_dir
echo pwd
both echo's will show different values.
In one reply they suggested using chdir. Do this!
Unless you use a fully qualified path name the user
can have an alias set that may render your system call useless.
It's always better to use library reference calls than using
system("something"); Calling command line function inside a compiled or
interpreted language has no garuntees if the function reacts the same
from user to user or if it even exists from node to node.
Also, many compilers come with built-in chdir(), so you can do this:
bool ErrorFlag = chdir("/sprat/blat");
if (!ErrorFlag)
system("galumph");
else
std::cout << "Oops, no such dir." << std::endl;
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)