I'm enumerating contents of a folder with FindFirstFile
/FindNextFile
. The problem I'm facing is that some of the sub-folders found cannot be enumerated in turn, FindFirstFile
returns "Access is denied." So I want to check for this condition and not include such-subfolders into the list in the first place. I've found two possible solutions: check the path with _access()
, or check the actual permissions in detail with AccessCheck
, but the latter is said to be heavy-weight, unlike _access()
, because you need to open and close a handle. Problem is, _access
always succeeds for all the folders that I can't enumerate with FindFirstFile
. Is there any other solution besides AccessCheck
?
Another head-on approach would be to call FindFirstFile
right away, but that, again, seems a waste (and I would also first need to determine whether the item is a folder, so even more extra work).
The comments on my question are helpful and provide the easiest solution to the problem as formulated, but during further research I've found that the folders I cannot enumerate are links, they have the attribute bit
FILE_ATTRIBUTE_REPARSE_POINT
set in theirWIN32_FIND_DATA::dwAttributes
field. Checking for that was enough for me to implement special handling for these items.