增加创建文件夹的统一接口
authorCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 11:59:43 +0000 (19:59 +0800)
committerCaisking <3449750381@qq.com>
Fri, 27 Sep 2024 11:59:43 +0000 (19:59 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h

index 5c5d51d..db029af 100644 (file)
@@ -1,11 +1,14 @@
 #include "uicomponents/UIComponents.h"
 #include <vector>
 #include  <string.h>
-#include <string>
 #include <iostream>
 #include "common/text.h"
 #include "common/typed_text.h"
 #include "font/ui_font.h"
+#include <sys/stat.h>  
+#include <sys/types.h>  
+#include <fcntl.h>  
+#include <unistd.h>  
 
 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());
+    }
+    }
    
 }
index ca024b0..41dccf9 100644 (file)
@@ -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