//inloadName 创建的文件夹名称
int setDownloadLoad(std::string inloadName) {
//用于存储模块路径
CHAR szMoudlePath[MAX_PATH];
//使用NULL参数,获取本模块路径
if (!GetModuleFileNameA(NULL, szMoudlePath, MAX_PATH))
{
printf("Get load failed\n");
return -1;
}
std::string folderPath = +szMoudlePath;
//查找在s1中任意一个字符在s中最后一次出现的位置,并返回(包括0)
int last = folderPath.find_last_of("\\");
int secLast = (folderPath.substr(0, last)).find_last_of("\\");
std::string finalFolderPath= folderPath.substr(0,secLast);
finalFolderPath += "\\";
finalFolderPath += inloadName;
if ((GetFileAttributesA(finalFolderPath.c_str()) == FILE_ATTRIBUTE_DIRECTORY))
{
printf( "Directory already exists.\n" );
return 0;
}
else {
bool flag = CreateDirectory(finalFolderPath.c_str(), NULL);
if (!flag)
{
printf("Directory created failed..\n");
return -1;
}
}
return 0;
}
在所在模块上一级目录创建一个文件夹
最新推荐文章于 2022-12-12 15:49:42 发布