1 /* 2 * Copyright (c) 2025 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 INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LISTFILE_CORE_H 17 #define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LISTFILE_CORE_H 18 19 #include <dirent.h> 20 21 #include "file_filter.h" 22 #include "filemgmt_libfs.h" 23 #include "fs_file_filter.h" 24 25 namespace OHOS::FileManagement::ModuleFileIO { 26 using namespace std; 27 28 struct NameListArg { 29 struct dirent **namelist = { nullptr }; 30 int direntNum = 0; 31 }; 32 33 constexpr int DEFAULT_SIZE = -1; 34 constexpr int DEFAULT_MODIFY_AFTER = -1; 35 struct OptionArgs { 36 FileFilter filter = 37 FileFilterBuilder().SetFileSizeOver(DEFAULT_SIZE).SetLastModifiedAfter(DEFAULT_MODIFY_AFTER).Build(); 38 int listNum = 0; 39 int countNum = 0; 40 bool recursion = false; 41 std::string path = ""; ClearOptionArgs42 void Clear() 43 { 44 filter.FilterClear(); 45 filter.SetFileSizeOver(DEFAULT_SIZE); 46 filter.SetLastModifiedAfter(DEFAULT_MODIFY_AFTER); 47 listNum = 0; 48 countNum = 0; 49 recursion = false; 50 path = ""; 51 } 52 }; 53 54 struct FsListFileOptions { 55 bool recursion = false; 56 int64_t listNum = 0; 57 optional<FsFileFilter> filter = nullopt; 58 }; 59 60 class ListFileCore { 61 public: 62 static FsResult<std::vector<std::string>> DoListFile( 63 const std::string &path, const optional<FsListFileOptions> &opt = nullopt); 64 }; 65 66 constexpr int FILTER_MATCH = 1; 67 constexpr int FILTER_DISMATCH = 0; 68 const int32_t MAX_SUFFIX_LENGTH = 256; 69 70 } // namespace OHOS::FileManagement::ModuleFileIO 71 #endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LISTFILE_CORE_H