I have made a program that stores a file like this:

ofstream out;
out.open("C:\\reg.txt");

This file is used everytime a program starts in order to find if the encrypted password is correct within this file.
This works without any problem on my computer, using XP Proffessional and where I know that I have a C:\\ path.

The big question for me now is, that I need to make this portable for the systems below as much as possible.
The problem is that you can never know if the current computer that run the program has a C:\\, F:\\, R:\\, O:\\ and so on...
This is unknown information as I understand.

So my question is how I will solve something like this so it also will work for the systems below wich also could use different paths ?


XP Proffessional
XP Home Edition
Windows Vista
Windows 98
Windows ME
Windows NT
Windows 2000
Windows server 2003

Ok, but that cant really be safe enough. If I have set C:\\ in my code and that computer uses D:\\ the application will not be possible to use because it depends on to find info on C:\\.

There must be any other solution to it but have difficult finding but is searching around..
Is it possible and correct to iterate through A:\\ --> Z:\\ to see if it exists and if it is okay to do this, how would it be possible to see if for example: C:\\ exists like File::Exists() ?


Perheps this is correct to do:

System::IO::Directory::Exists("C:\\");

It's generally a safe bet that the Windows systems you listed will have a C: drive.

Perhaps Windows API? Considering all those platforms are Windows, there is a GetLogicalDriveStrings() function available although the minimum supported Client is Windows 2000, so that'd rule Win 98 out. (Or atleast, not guantee it would work properly)

If GetLogicalDriveStrings is used, it'd also probably be a good idea to use in conjunction with GetDriveType() function to seperate what is actually a fixed HDD, removable HDD, CD/DVD ROM & so on.

You could always use a function more like GetSystemDirectory() which will get the operating systems "system directory" then use .resize(3) to resize the string down to just the drive root.

Lastly, if wanted you can use GetFileAttributes() from the Windows API which also works with directories, check the remarks section of that link to see how to use with mounted volumes.

That is all assuming you can/want to use the Windows API to some extent. (I made the assumption based on them all being Windows Platform)

You are right, I will use this command and this will find the correct folder on the computer..

System::Environment::GetFolderPath()

SUGGESTION :

use SpecialFolder for app settings..

This article has been dead for over six months. Start a new discussion instead.