For a CLR type program in Visual C++, I need to record the file date of the version of the program being run. That seems like a very normal thing to do but I can't find a solution (that works) on the web.
I'm able to read the date of any file from within my program (not easy by the way) but it needs the absolute path. (In this case to the very program being run.)
On the web I found two suggestions neither of which work probably because I am so unfamiliar with Windows programming.
1. Path.GetDirectoryName(Application.ExecutablePath);
I don't understand the error messages (What's a UDT?) and pressing F1 on any of those entities is of no use to a beginner because the MSDN help is so terse. (Their examples don't work either.)
2. get_module_directory(filebuf, sizeof(x) / sizeof((x)[0]) ); strikes error C2248 and F1 on this function is "No Information Available"

-> Can anyone show what's needed in the way of a #include or declaration to get those to work?
-> Is there an eaiser way to get the path to the program you are in?

Recommended Answers

All 2 Replies

Assembly::GetExecutingAssembly()->Location; will give you the full path of the running program. The 'file date' isn't specific enough. Do you want the creation time, the last read, last write? But the File class has that stuff:

String^ path = Assembly::GetExecutingAssembly()->Location;
DateTime^ fileDate = File::GetCreationTime(path);

Wow,
Thanks Tom.
Both worked.
For those who are even more beginner than me, you have to add using namespace System::Reflection;
at the top.
And F1 on that function helped me find its sister function, GetLastWriteTime().
Thanks again Tommy Gunn.
And for everyone else who benefits from this, don't forget you can click on "Add to Tom Gunn's Reputation" too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.