Cyber-Dragon
asked on
C++ Get Self File Name, Extension and Path
Hi I'm currently working on an application where I need to make a copy of the application in another directory from the current directory. While I have the copying part down, I can't seem to figure out how I would find the current path, file name and extension of the EXE thats running so that I can pass it to the function.
void main ()
{
Copy();
}
void Copy()
{
// _MAX_PATH is the maximum length allowed for a path
char CurrentPath[_MAX_PATH];
GetCurrentPath(CurrentPath);
//The complete path needs to go to this function.
std::ifstream in (CurrentPath,ifstream::binary); // open original file
std::ofstream out("c:/New.exe",ofstream::binary); // open target file
out << in.rdbuf(); // read original file into target
out.close(); // explicit close, unnecessary in this case
in.close();// explicit close, unnecessary in this case
}
//Currently using this to fine the path but this only returns the directory.
void GetCurrentPath(char* buffer)
{
getcwd(buffer, _MAX_PATH);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.