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 #ifndef DIRECTORY_EX_H 17 #define DIRECTORY_EX_H 18 19 #include <string> 20 #include <vector> 21 #include <sys/stat.h> 22 23 namespace OHOS { 24 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 ExcludeTrailingPathDelimiter function exclude the end '/' from the strPath, 52 * return the path without the end '/'. 53 */ 54 std::string ExcludeTrailingPathDelimiter(const std::string& path); 55 56 /** 57 * The IncludeTrailingPathDelimiter function include the end '/' from the strPath, 58 * return the path with the end '/'. 59 */ 60 std::string IncludeTrailingPathDelimiter(const std::string& path); 61 62 /** 63 * The GetDirFiles function get all files in the path. 64 */ 65 void GetDirFiles(const std::string& path, std::vector<std::string>& files); 66 67 /** 68 * The IsEmptyFolder function judge the path is empty, 69 * return true if is empty, else false. 70 */ 71 bool IsEmptyFolder(const std::string& path); 72 73 /** 74 * The ForceCreateDirectory function is force create the dir with subdir, 75 * return true if create succ, else false. 76 */ 77 bool ForceCreateDirectory(const std::string& path); 78 79 /** 80 * The ForceRemoveDirectory function is force delete the dir with subdir and files, 81 * return true if remove succ, else false. 82 */ 83 bool ForceRemoveDirectory(const std::string& path); 84 85 /** 86 * The RemoveFile function is remove the input strFileName, 87 * return true if remove succ, else false. 88 */ 89 bool RemoveFile(const std::string& fileName); 90 91 /** 92 * The GetFolderSize function is get the folder size(bytes). 93 */ 94 uint64_t GetFolderSize(const std::string& path); 95 96 /** 97 * The ChangeModeFile function is change the input file authority, 98 * return true if change succ, else false. 99 */ 100 bool ChangeModeFile(const std::string& fileName, const mode_t& mode); 101 102 /** 103 * The ChangeModeDirectory function is change the input Directory authority, include subdir, 104 * return true if change succ, else false. 105 */ 106 bool ChangeModeDirectory(const std::string& path, const mode_t& mode); 107 108 /** 109 * The PathToRealPath function is get real path from relative path, 110 * return true if change succ, else false. 111 */ 112 bool PathToRealPath(const std::string& path, std::string& realPath); 113 } // OHOS 114 #endif