C++ Code Sample: Get Total Items in Folder
C++ Code Sample: Get Total Items in a Folder
Liệt kê các file có trong một folder sắn có, chức năng này thường được sử dụng nhiều trong các phần mềm cơ bản.
Hãy cùng xem mẫu code cho chức năng này.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <vector> #include <windows.h> #include <string> std::vector<std::string> GetItemsFolder(std::string path) { WIN32_FIND_DATA find_data; std::vector<std::string> file_list; wchar_t* file_path = StringToWchar(path); HANDLE hFind = FindFirstFile(file_path, &find_data); file_list.push_back(WcharToString(find_data.cFileName)); while (FindNextFile(hFind, &find_data)) { std::string str = WcharToString(find_data.cFileName); file_list.push_back(str); } return file_list; } |