How to get THE PATH of a newly created file C++?

closed account (3hMz8vqX)
Hi all,
How to get THE PATH of a newly created file C++?

That means my program will run in the background and if I
right click -> New Text Doc
a new file is created, right?
So my goal is that my program should get the path of that newly created file and store its path to a text document!

Thankyou everyone in advance!!! :)
It's not exactly what you're looking for but "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\..." will give you a list of the recently opened documents. Otherwise I suspect you're looking at hooking the "CreateFile()" function which is messy.
closed account (3hMz8vqX)
Thankyou computergeek01!
Okay then how will you get the path of a newly created .EXE
or opened .EXE using C++?
This is not a question about language, but a question about the Desktop Manager or OS.

You click with mouse some GUI element (of Windows Explorer), as a result some program executes. Only the Windows Explorer knew what it was doing. You select "Save" from Notepad. Notepad knows what it does, and so does the OS kernel/filesystem.

The question is, how can you ask them? Can you? Apparently yes: the antivirus applications can hook into the system calls and intercept file access. Presumably the OS documents the API to do so. Find that documentation.


Looking from other angle, you have a program, it runs, and asks where its own file actually is. Even that is not trivial on all platforms.
Okay then how will you get the path of a newly created .EXE
or opened .EXE using C++?


What EXE ? Your actual program that is running ?

If so, then just call GetModuleFileName() API:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v=vs.85).aspx

1
2
3
4
5
TCHAR szPath[MAX_PATH];

    GetModuleFileName( "", szPath, MAX_PATH ) ;

// use szPath from now on 



Alternatively, try this, but it could not work on all compilers:
The global variable _pgmptr is automatically initialized to the full path of the executable file, and can be used to retrieve the full path name of an executable file.
Topic archived. No new replies allowed.