C/C ++ generates a folder, deletes a folder, and obtains the path of the running file.

Source: Internet
Author: User

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:

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.