c ++ Determine whether the folder exists and create a folder

<io.h>
Function Prototype: int _access (const char * pathname , int mode);
Parameters: pathname for the file or directory path for the access path mode (use in different systems may not be re-defined macro definition)
Return value: If the file has the specified access permission, the function returns 0; if the file does not exist or cannot access the specified permission, it returns -1.
Remarks: When pathname is a file, the _access function determines whether the file exists and determines whether the file can be used The mode specified by the mode value is accessed. When pathname is a directory, _access only determines whether the specified directory exists. In Windows NT and Windows 2000, all directories only have read and write permissions.
The value and meaning of mode are as follows:
0-only check whether the file exists
2-write permission
4-read permission
6-read and write permission

#include <direct.h>
mkdir Create a folder
rmdir Delete a folder
Example code:
#include
#include <direct.h>
#include <io.h>
#include <stdio.h>
#include <string.h>
using namespace std;
void main ()
{
string save_test_mask_ellipse_path = "H: / fetal ultrasound image head circumference measurement / test_mask_ellipse";
if (access (save_test_mask_ellipse_path.c_str (), 0) == -1)
{
mkdir (save_test_mask_ellipse_path.c_str ( )); // Save folder

}

}

Published 36 original articles · won praise 1 · views 6384

Guess you like

Origin blog.csdn.net/qq_34291583/article/details/96437355