如何使用findfirstfile和findnextfile? [英] How to use findfirstfile and findnextfile?

查看:103
本文介绍了如何使用findfirstfile和findnextfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

谁能帮我了解findfirstfile和findnextfile的工作原理吗?

我只是不明白,无法链接到从头开始解释它的页面.

解决方案

阅读以下内容:
MSDN:FindFirstFile函数 [MSDN:FindNextFile函数 [ http://msdn.microsoft.com/en-us/library/aa365200 (v = vs.85).aspx [
该句柄上的后续FindNext()继续遍历列表,直到列表用尽(然后,在幕后,操作系统每次都会使您沿着列表移动)

确保您调用FindClose();从本质上讲,它告诉操作系统您已经完成了列表,并且可以放手-无需在结束之前重复进行最后操作(例如,您正在寻找特定的文件大小,则可以找到该列表)它,您可以使用FindClose()提前终止列表.

Hello.

Can anyone help me understand how findfirstfile and findnextfile work?

I just don''t get it and am unable to link to a page that explains it from scratch.

解决方案

Read these:
MSDN: FindFirstFile Function[^] and MSDN: FindNextFile Function[^]


You call FindFirstFile to set up a file specification to look for.
You can then call FindNextFile repeatedly (normally in a loop) to iterate through each file that matches the specification.

I don''t think you googled too hard: your question subject led me straight to MSDN and an example:
http://msdn.microsoft.com/en-us/library/aa365200(v=vs.85).aspx[^]


I understand your frustration - some ways of doing things are not untuitive to all ...

Ok - the fundamental problem with a directory listing is it''s variable length, and it can be enormous, the way findfirst/next works is

FindFirst() starts a new query off, given a search string, that query is represented by the handle you get returned, then calling FindNext() with the handle you get, takes you to the next item on the result list (and under the hood, the OS ''remembers'' you''re moved down the list)

Subsequent FindNext()s on that handle continue to traverse the list until it''s exhausted (and again, under the hood, the OS moves you along the list each time)

Make sure you call FindClose(); that essentially tells the OS you''ve finished with the list and it can let it go - you don''t have to iterate to the end before you do a close (say you''re looking for a particular filesize, you find it, you can terminate the list early with a FindClose()


这篇关于如何使用findfirstfile和findnextfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆