C++ Get Self File Name, Extension and Path

Posted on 2009-04-16
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
    LVL 9

    Accepted Solution


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now