Re: How do you use FindFirstFile ?



On Tue, 19 Jul 2005 13:13:58 -0700, "Eugene Gershnik"
<gershnik@xxxxxxxxxxx> wrote:

>Timothy Madden wrote:
>>
>> What I actualy need is to see if a file exists and the only documented
>> way to do it that I could find is to use SearchPath.
>
>The only documented way to check for file existence is to open the file. Why
>doesn't it work for you?

GetFileAttributes() is somewhat more reliable and faster, as it will
succeed if the file exists and is accessible (per security/ACL), while
opening the file will fail if it is opened by another process without
appropriate sharing.

FindFirstFile and the _stat family from the CRT (which I believe
eventually call FindFirstFile) are other possibilities, but measurably
slower than GetFileAttributes.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.



Relevant Pages

  • Re: How do you use FindFirstFile ?
    ... >> The only documented way to check for file existence is to open the ... > GetFileAttributes() is somewhat more reliable and faster, ... > appropriate sharing. ... > eventually call FindFirstFile) are other possibilities, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How do you use FindFirstFile ?
    ... >> The only documented way to check for file existence is to open the file. ... > GetFileAttributes() is somewhat more reliable and faster, ... > eventually call FindFirstFile) are other possibilities, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How do you use FindFirstFile ?
    ... >>> The only documented way to check for file existence is to open the ... >> GetFileAttributes() is somewhat more reliable and faster, ... >> eventually call FindFirstFile) are other possibilities, ... checking if thousands of file specs listed in a database ...
    (microsoft.public.win32.programmer.kernel)
  • Re: DeleteFile fails unexpectedly
    ... Could it be that you pass a file with a wildcard to FindFirstFile()? ... You could check GetFileAttributes() - smaller code, and you get the type of ... > error returned from DeleteFile() is '2' which happens to be "The system ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Problem with GetAttr()
    ... While you're right, GetFileAttributes still fails, if you're just using it ... to determine the existence of a file, his FileExists code will handle that ... But the APIs fail just as well with "C:\pagefile.sys" and ... They all fail on the above mentioned files ...
    (microsoft.public.vb.general.discussion)