External File commands

Hi guys,
So I've been trying to make a program that is placed on my external hard drive. It contains 5 folders which 3 require passwords. Although when I open the files using the system("K:\Master\School"); line, it sometimes just opens the C:\. I know it's because the driver's letter changes between computers and so I am in need of help for a line that either changes the letter, finds the files path, or any other way possible to open it. And if possible, will this work if the files are made hidden?
Is your program running from the external drive? If so, just omit the drive letter and colon and start with a slash.

Also, the 'hidden' property on files doesn't do anything - just that Windows Explorer won't display the it unless you have a setting changed.
Thanks for the quick reply LB,
But I already tried that. I'm talking about when the external hard drive is removed and plugged into another computer. Since it assigns it the next available letter. For example, my home laptop assigns it as "K:\" yet the computers at my school range from "D:\" to "E:\" to "H:\". I may of not been clear, is there a code that FINDS the path for the folders or just changes the letter of the driver? Maybe to a letter than would hardly be used such as "Z:\"?
Please answer my question: Is your program running from the external drive?

If not, you are extremely limited on options.
To Expand on LB's statement, you're limited to using FindFirstVolume and FindNextVolume and trying every path available on the machine or similar methods.
Yes it is being run from the external drive. Is there a code that will find the path regardless of the drivers assigned letter? The setup is a folder named "Master" which has the 5 sub folders which include "School", "Programming" and "Movies". The master folder will be made hidden and the program will autorun when the external drive is plugged in. The program asks for the folder and if required, a password. Yet I've been having trouble getting the driver as the same letter in the code. And sometimes it just opens the C:\ regardless of what you write
NDprogramming wrote:
Yes it is being run from the external drive. Is there a code that will find the path regardless of the drivers assigned letter?
LB wrote:
just omit the drive letter and colon and start with a slash.


std::string path = "/path/to/file.txt";
Last edited on
I tried std::string path = "/path/to/file.txt"; and nothing happens. I tried using system("explorer \Master\School"); and it still opens C:\
I'm trying to open a folder, not a file, if that helps at all?
Last edited on
You need to make sure the path starts with a slash.

Never use backslashes \
Instead, always use forward slashes /
I tried using forward slashes in both lines, neither worked. The
std::string path = "/path/to/file.txt";
does nothing. And
system("explorer /Master/School");
opens the My Documents within the C:\..?
Of course the std::string path = "/path/to/file.txt"; does nothing, it is just an example of a string containing the path.

Try quoting the path:

system("explorer \"/Master/School\"");
Just tried and it always bring up "C:\Users\Nick\Documents".
This is the block of code that opens the School Folder:
 if(menu_option=="school"||menu_option=="School")
    {
        cout << "No Password Required\n\n";
        system("explorer \"/Master/School\""); //problem here
        delay();
    }
    else{}
I've also gone into cmd and typed in the command "explorer K:\Master\School" and it opens the correct folder. Although if I am to use that, and go to another computer I again have the problem of the assigned letter being different.
Last edited on
Please be certain you are running the program from the external drive. Try creating a text file with nothing in it just to see where it gets created - if it gets created somewhere other than the external drive, you are not running the program correctly.
I ran
std::ofstream fs("test.txt");
in it, and it creates the file inside the folder where main.cbp is located. And I cant move the Master Folder inside where it is because the program is located inside the Master folder.
Don't run the program from your IDE, run it from the external drive. That means copy or move the executable there and run it.
So now it doesn't create the file at all. Neither the C:\ or on the external drive.
You're sure? Try std::ofstream fs("/test.txt"); and check the root of all your drives.
I ran both code lines
std::ofstream fs("/test.txt");
and
system("explorer /Master/School");
. It only created the test.txt and opened up C:/Users/Nick/Documents. The test.txt file was created where the main.exe was placed, which was outside of the Master folder but still on the external drive.
Topic archived. No new replies allowed.