From: Caisking <3449750381@qq.com> Date: Fri, 27 Sep 2024 11:59:43 +0000 (+0800) Subject: 增加创建文件夹的统一接口 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=31ad79217c1292d9859df80883a71a4b8d67cf8d;p=mirrors%2FFD230.git 增加创建文件夹的统一接口 --- diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 5c5d51daf..db029afaf 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -1,11 +1,14 @@ #include "uicomponents/UIComponents.h" #include #include -#include #include #include "common/text.h" #include "common/typed_text.h" #include "font/ui_font.h" +#include +#include +#include +#include namespace OHOS { @@ -890,5 +893,23 @@ namespace OHOS } printf("%s\r\n",str_); } + + /*创建文件夹*/ + void CreateDirectoryIfNotExists(const std::string &path) { + struct stat info; + if (stat(path.c_str(), &info) != 0) { + if (mkdir(path.c_str(), 0755) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Error: Could not create directory %s. Errno: %d", + path.c_str(), errno); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", + path.c_str()); + } + } else if (info.st_mode & S_IFDIR) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", + path.c_str()); + } + } } diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index ca024b07d..41dccf9c3 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -304,6 +304,8 @@ namespace OHOS void updata_char(char *str_,char *str,uint32_t max_len); + void CreateDirectoryIfNotExists(const std::string &path); + #endif } // namespace OHOS