views:

115

answers:

2

hello how can I set the current drive in c++? this is how I set the directory but i'm unable to change the drive like this(duh) but I cant find anything on the msdn site...

anybody know this?

thanks

+2  A: 

The string you use to set the directory can be prefixed by the drive letter -- i.e., "c:\program files".

Directories are set relative to your programs current working directory. If you start your program from 'X' drive you will not be able to move outside of 'X' using relative conventions/directory addressing. You need to use a directory string prefixed with the correct drive letter.

Hassan Syed
so if I run the program from drive XI should be able to do this?setCurrentDirectory("Y:/test");?
mars
With a backslash, yes. The doc mentions you should have a trailing backslash too.
Carl Smotricz
Yes that should work, trailing backslash is good convention.
Hassan Syed
It DOES! work!... thanks guys, I had tried it befor but didn't debug correctly thanks!
mars
Woohoo my first accepted answer :P thanks and you welcome :D
Hassan Syed
+2  A: 

According to thr MSDN docs on the Win API, SetCurrentDirectory will also set the current drive.

Carl Smotricz