C/C ++ generates a folder, deletes a folder, and obtains the path of the running file.
I recently used MFC to develop an interface. One requirement is to generate a folder with the same name as the executable file (exe file). For example, my executable file path is D: \ KFS \ codes \ 22222 \ Release \ 22222.exe. I need to generate a folder named 22222 IN THE D: \ KFS \ codes \ 22222 \ Release path to store things. After reading a bit of information, I succeeded. Then I wrote a demo. The code below:
# Include
# Include
# Include
Using namespace std; int main () {char chpath [MAX_PATH]; GetModuleFileName (NULL, (LPSTR) chpath, sizeof (chpath); // obtain the path of the exe file cout <
The code is very simple. All the functions that need attention are commented out. Another point is that in VS2010, after a new project is created, an error occurs during compilation.
Error C2664: "GetModuleFileNameW": the conversion of parameter 2 from "LPSTR" to "LPWSTR" is not related to the type to which it is directed. Conversion requires reinterpret_cast, C style conversion, or function style conversion.
It is because the Unicode character set is used by default. Solution: Right-click "--" attribute "--" Configure number type "--" general "--" Character Set "and choose" not set "--" OK.
Result chart: