views:

30

answers:

1

Is there any "built-in" way to access the parent drive "relatively" on Windows?

i.e, instead of my program storing a path like K:\1\2\3 (K:\ being a USB flash drive), I'd like it to store the path without the drive letter, that way if the drive letter happens to change in the future, the stored path will still be valid because it's dynamic.

I know I can manually replace the drive letter with something like Flash:\ before storing the path, and then before accessing the stored path, replace Flash:\ with the letter of the drive that my program is currently running on, but I wanted to know if there was a "built-in" way to do this, where I could just pass a certain string to Windows in place of the drive letter and Windows would automatically replace it with the drive letter that the current program is running on.

+2  A: 

Try just using \1\2\3\

Daniel A. White
D'oh! I tried that first before asking here, and it didn't work. Reason it didn't work: SHGetFileInfo() doesn't like that type of path, for whatever reason. Works fine with fopen(), though, which I didn't think to try. Thanks!
This might run into problems: the volume that a relative directory might be applied to is not necessarily the volume that the program executable is on (in other words,the current directory that this path might be applied to might be on a different drive than the program image).
Michael Burr
@Michael Burr: Thanks, so then perhaps I should replace the first \ with the drive letter used in argv[0] (the program executable path)?