c++ - when to call _findclose? -
Note: Since the problem has been solved, I have added comments to my original posts. According to "", it has been said: * You end up using _findfirst or _findnext function (or any form) after you call _findclose should do. This frees up resources used by these functions in your application. * - Note: This is unclear, but what Microsoft is trying to say: Some users need to find the first file (they do not need to call _findnext ), Then call _findclose; Some users are called _findnext (they are already called _findfirst), after finishing using them, call _findclose. In fact, _FindNext can be called multiple times, while _FindCalues is responsible for only one handle, which is made by _findfirst. and the following is a piece of code that is widely used for the list of files in the directory. - Comment: That's right. For example, if the directory contains 2 files and 1 directory then: _findfirst is called once. The handle is a compatible fileinfo system directory. " (Is this correct?) - Comment: No handle files are a group of directories, fileinfo acting as "cursor" (Fileinfo is always a "name" field, I bet Imposing that using the "name" in the implementation of _findnext, the group of files is next in directories specified by the operators +) _findnext is called 4 times. (The first argument is always handled with ".", Is it correct?) - Comment: Yes + No first argument is always the same handle; The handle does not conform to any fileinfo, but for a group of them. My questions are: Is it enough to say "_findclose" once? - Comment: * Yes. If _findnext handle will not change the value, how will it "remember" where is the next file to start or directory? (Sorry, maybe I was thinking in the "linked list" pattern.) * - Comment: * I bet that the fileinfo's name is using the field. Just as a Windows Explorer, we sort the content in a folder, give the file name, we can know their position in the list, so we can "Search the next". Is there any disadvantage? Call the Fundclose more than once? (Like an accident or something) * - Comment: * Excuse a stupid question! Or is the following code wrong? If so, what is the right way to implement it? - This is the right code. - Comment: Sorry the use of "guarantee" is not very easy. This is where the bug is. Note: I have no problem understanding what the handle is, such as open a file, read / write / read / write ..., close the file handle < Strong> - Comment: Go to improve your english. Thank you in advance. Mail to call your call to _findclose on In the code above, because you only have to If you were performing a recursive search of the subdirectory, you would end up with multiple calls as
. .. ddd file1.txt file2.txt
// List of directories files intptr_t; _finddata_t filed; File = _findfirst (desc.c_str (), and filed); If (file! = -1) {do {cout & lt; & Lt; Fileata.name & lt; & Lt; Endl; // Enter the name of the file in a vector here} (_findnext (file, and file) == 0); } And {cout & lt; & Lt; "No description file found" & lt; & Lt; Endl; } _FundCLOS (file); I asked him because I have met an issue that an application is freeing a directory which can not be removed if the process is alive. However, I can guarantee that "_findclose" is said to be from "_findfirst" on every return value if I add "_findclose" after calling "_findnext", then this issue will be completely fixed to you How Can I Help Me Explain?
_findfirst You should do - that is, whenever you call
_findfirst , you should have a mailing call at
_findclose .
_findfirst , it is correct to make a call on
_findclose .
_findfirst as you descend the hierarchy, and
_findclose After you call, you end up and back up the hierarchy.
Comments
Post a Comment