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 <sys/stat.h> 21 #include <vector> 22 23 namespace OHOS { 24 /** 25 * The GetCurrentProcFullFileName function get the current process exe name. 26 */ 27 std::string GetCurrentProcFullFileName(); 28 29 /** 30 * The GetCurrentProcPath function get the current process exe path. 31 */ 32 std::string GetCurrentProcPath(); 33 34 /** 35 * The ExtractFilePath function extract the input file path. 36 */ 37 std::string ExtractFilePath(const std::string& fileFullName); 38 39 /** 40 * The ExtractFilePath function extract the input file name. 41 */ 42 std::string ExtractFileName(const std::string& fileFullName); 43 44 /** 45 * The ExtractFileExt function extract the input file name type. 46 */ 47 std::string ExtractFileExt(const std::string& fileName); 48 49 /** 50 * The ExcludeTrailingPathDelimiter function exclude the end '/' from the strPath, 51 * return the path without the end '/'. 52 */ 53 std::string ExcludeTrailingPathDelimiter(const std::string& path); 54 55 /** 56 * The IncludeTrailingPathDelimiter function include the end '/' from the strPath, 57 * return the path with the end '/'. 58 */ 59 std::string IncludeTrailingPathDelimiter(const std::string& path); 60 61 /** 62 * The GetDirFiles function get all files in the path. 63 */ 64 void GetDirFiles(const std::string& path, std::vector<std::string>& files); 65 66 /** 67 * The IsEmptyFolder function judge the path is empty, 68 * return true if is empty, else false. 69 */ 70 bool IsEmptyFolder(const std::string& path); 71 72 /** 73 * The ForceCreateDirectory function is force create the dir with subdir, 74 * return true if create succ, else false. 75 */ 76 bool ForceCreateDirectory(const std::string& path); 77 78 /** 79 * The ForceRemoveDirectory function is force delete the dir with subdir and files, 80 * return true if remove succ, else false. 81 */ 82 bool ForceRemoveDirectory(const std::string& path); 83 84 /** 85 * The RemoveFile function is remove the input strFileName, 86 * return true if remove succ, else false. 87 */ 88 bool RemoveFile(const std::string& fileName); 89 90 /** 91 * The GetFolderSize function is get the folder size(bytes). 92 */ 93 uint64_t GetFolderSize(const std::string& path); 94 95 /** 96 * The ChangeModeFile function is change the input file authority, 97 * return true if change succ, else false. 98 */ 99 bool ChangeModeFile(const std::string& fileName, const mode_t& mode); 100 101 /** 102 * The ChangeModeDirectory function is change the input Directory authority, include subdir, 103 * return true if change succ, else false. 104 */ 105 bool ChangeModeDirectory(const std::string& path, const mode_t& mode); 106 107 /** 108 * The PathToRealPath function is get real path from relative path, 109 * return true if change succ, else false. 110 */ 111 bool PathToRealPath(const std::string& path, std::string& realPath); 112 } // OHOS 113 #endif 114