A method to auto-update the directory of a file using C++ ?
I have a program which aims to first input the password from the user, and once the password matches, the program will open a file using the ShellExecute() function.
This file is a C++ executable file in .exe format.
The program needs to automatically update the directory in the ShellExecute() function instead of having the programmer or other users manually change it in the code each time the executable file's location is changed. What is the best approach to do so ? I have gone through some of these links, but to no avail :
[1] Finding the last created FILE in the directory, C++
[2] How do I make a file self-update (Native C++)
[3] https://www.daniweb.com/programming/software-development/threads/242600/finding-the-most-recently-created-file-in-a-folder
Please feel free to browse my code provided below :
#include<iostream>
#include<conio.h>
#include<string.h>
#include<unistd.h>
#include<windows.h>
using namespace std;
int main(void)
{
string pw="";
char ch;
int attempts=3;
Initiation:
system("cls");
cout<<"Password ?\n--> ";
ch=_getch();
while(ch!=13)
{
pw.push_back(ch);
cout<<'*';
ch=_getch();
}
if(pw=="a32bx#$123")
{
ShellExecute(NULL, "open", "C:\\Users\\agm\\Documents\\easypeasy.exe", NULL, NULL, SW_SHOWDEFAULT);
}
else if(pw!="a32bx#$123")
{
attempts--;
if(attempts>0)
{
cout<<"\n\nIncorrect password. You now have "<<attempts<<" attempts remaining. Loading back the main screen...";
sleep(3); //This gives time for the user to read the line before it moves to the label named Initiation.
goto Initiation;
}
if(attempts==0)
cout<<"\n\nAborting now !";
}
} //END OF CODE
Note : I'm also open to any suggestions on how to improve the overall code.