1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17 #ifndef DIRECTORY_EX_H 18 #define DIRECTORY_EX_H 19 20 #include <string> 21 #include <vector> 22 #include <sys/stat.h> 23 24 namespace OHOS { 25 /** 26 * The GetCurrentProcFullFileName function get the current process exe name. 27 */ 28 std::string GetCurrentProcFullFileName(); 29 30 /** 31 * The GetCurrentProcPath function get the current process exe path. 32 */ 33 std::string GetCurrentProcPath(); 34 35 /** 36 * The ExtractFilePath function extract the input file path. 37 */ 38 std::string ExtractFilePath(const std::string& fileFullName); 39 40 /** 41 * The ExtractFilePath function extract the input file name. 42 */ 43 std::string ExtractFileName(const std::string& fileFullName); 44 45 /** 46 * The ExtractFileExt function extract the input file name type. 47 */ 48 std::string ExtractFileExt(const std::string& fileName); 49 50 /** 51 * The TransformFileName function transform the input file name for windows or mac. 52 */ 53 std::string TransformFileName(const std::string& fileName); 54 55 /** 56 * The ExcludeTrailingPathDelimiter function exclude the end '/' from the strPath, 57 * return the path without the end '/'. 58 */ 59 std::string ExcludeTrailingPathDelimiter(const std::string& path); 60 61 /** 62 * The IncludeTrailingPathDelimiter function include the end '/' from the strPath, 63 * return the path with the end '/'. 64 */ 65 std::string IncludeTrailingPathDelimiter(const std::string& path); 66 67 /** 68 * The GetDirFiles function get all files in the path. 69 */ 70 void GetDirFiles(const std::string& path, std::vector<std::string>& files); 71 72 /** 73 * The IsEmptyFolder function judge the path is empty, 74 * return true if is empty, else false. 75 */ 76 bool IsEmptyFolder(const std::string& path); 77 78 /** 79 * The ForceCreateDirectory function is force create the dir with subdir, 80 * return true if create succ, else false. 81 */ 82 bool ForceCreateDirectory(const std::string& path); 83 84 /** 85 * The ForceRemoveDirectory function is force delete the dir with subdir and files, 86 * return true if remove succ, else false. 87 */ 88 bool ForceRemoveDirectory(const std::string& path); 89 90 /** 91 * The RemoveFile function is remove the input strFileName, 92 * return true if remove succ, else false. 93 */ 94 bool RemoveFile(const std::string& fileName); 95 96 /** 97 * The GetFolderSize function is get the folder size(bytes). 98 */ 99 uint64_t GetFolderSize(const std::string& path); 100 101 /** 102 * The ChangeModeFile function is change the input file authority, 103 * return true if change succ, else false. 104 */ 105 bool ChangeModeFile(const std::string& fileName, const mode_t& mode); 106 107 /** 108 * The ChangeModeDirectory function is change the input Directory authority, include subdir, 109 * return true if change succ, else false. 110 */ 111 bool ChangeModeDirectory(const std::string& path, const mode_t& mode); 112 113 /** 114 * The PathToRealPath function is get real path from relative path, 115 * return true if change succ, else false. 116 */ 117 bool PathToRealPath(const std::string& path, std::string& realPath); 118 } // namespace OHOS 119 120 #endif // DIRECTORY_EX_H 121