In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to achieve C++ programming using findfirst and findnext to find and traverse files". In daily operation, I believe many people have doubts about how to achieve C++ programming to find and traverse files using findfirst and findnext. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve C++ programming using findfirst and findnext to find and traverse files". Next, please follow the editor to study!
Catalogue
First, take a look at a file structure:
Use _ findfirst and _ findnext to find files
Both of these functions are in io.h.
First, take a look at a file structure: struct _ finddata_t {unsigned attrib; time_t time_create; time_t time_access; time_t time_write; _ fsize_t size; char name;}
Time_t is actually long.
And _ fsize_t, which is unsigned long.
Now let's explain the data members of the structure.
Attrib, which is the attribute of the file you are looking for:
_ A_ARCH (archived), _ A_HIDDEN (hidden), _ A_NORMAL (normal),
_ A_RDONLY (read-only), _ A_SUBDIR (folder), _ A_SYSTEM (system).
Time_create, time_access, and time_write are the time the file was created, the last time the file was accessed, and the last time the file was modified.
Size: file siz
Name: file name.
Use _ findfirst and _ findnext to find files
1. _ findfirst function: long _ findfirst (const char *, struct _ finddata_t *)
The first parameter is the file name, and you can use "*. *" to find all files, or "* .cpp" to find .cpp files. The second parameter is the _ finddata_t structure pointer. If the search is successful, the file handle is returned; if it fails,-1 is returned.
2. _ findnext function: int _ findnext (long, struct _ finddata_t *)
The first parameter is the file handle, and the second parameter is also the _ finddata_t structure pointer. If the lookup is successful, it returns 0, and if it fails, it returns-1.
3. _ findclose () function: int _ findclose (long)
There is only one parameter, the file handle. If the shutdown successfully returns 0, the failure returns-1.
# include # include # include using namespace std;bool transfer (string fileName, int exeNum); void dfsFolder (string folderPath, ofstream & fout); int main () {_ finddata_t file; int k; long HANDLE; k = HANDLE = _ findfirst ("*. *", & file); while (k! =-1) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.