C++ Get Self File Name, Extension and Path

Posted on 2009-04-16
Medium Priority
Last Modified: 2013-12-14
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 () 
void Copy()
	// _MAX_PATH is the maximum length allowed for a path
	char CurrentPath[_MAX_PATH];
//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);

Open in new window

Question by:Cyber-Dragon
1 Comment

Accepted Solution

JohnGaby earned 2000 total points
ID: 24163249

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question