Two ways to automatically create folders

Source: Internet
Author: User

two ways to automatically create folders

1, CreateDictionary ()

CreateDirectory (MyPath, 0); Create a folder for this app in the Temp folder

The prototype is: BOOL WINAPI createdirectory (__in lpctstr lppathname, __in lpsecurity_attributes lpsecurityattributes);

Where Lppathname is the path to the directory to be created, and the 2nd involves a security issue null is OK

For example:

Char "" ; GetTempPath (MAX_PATH, PATH); // Find the path of the temporary directory of the native and coexist in the character array path, MAX_PATH represents the maximum length of the character array CString MyPath = path + CString ("processassistantfile\\"); // Add the name of the new folder after the path 0 // Create a folder for this app in the Temp folder

_mkdir to create a new subdirectory

It is important to note that Windows _mkdir () requires only a path parameter, prototype: int _mkdir (const char* dirname);

EG1:

void CreateFolder (constchar* folder) {    _mkdir (folder);}

EG2: In the form of a system command, that is, systems (), in the header file stdio.h

#include <iostream>#include<string>#include<cstdlib>using namespacestd;intMain () {intCounter =0;  while(1)    {        stringStringdir ="ABCDEF"+counter; System ("mkdir"+stringdir). C_STR ());//c_str () converts the string type to char* type, GetBuffer () turns the CString type to char* typecounter++; }}

The Linux mkdir () requires two parameters, the first is the path, the second is the permission

int mkdir (const char* path,mode_t mode);

#include <sys/types.h><sys/stat.h>

... int = mkdir ("/home/cnd/mod1", S_irwxu | S_irwxg | S_iroth | S_ixoth);

You can also use system commands, that is, systems (), in the header file stdio.h

void CreateFolder (constchar* folder) {    char str[] ;     " mkdir%s " // folder is the name of the incoming file to be created, sprintf can connect the statement     System (STR);   // Create Folder }

Two ways to automatically create folders

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.