How can we check if a file Exists or not using Win32 program?

后端 未结 7 1591
傲寒
傲寒 2020-11-27 05:16

How can we check if a file Exists or not using a Win32 program? I am working for a Windows Mobile App.

7条回答
  •  感动是毒
    2020-11-27 05:52

    Another more generic non-windows way:

    static bool FileExists(const char *path)
    {
        FILE *fp;
        fpos_t fsize = 0;
    
        if ( !fopen_s(&fp, path, "r") )
        {
            fseek(fp, 0, SEEK_END);
            fgetpos(fp, &fsize);
            fclose(fp);
        }
    
        return fsize > 0;
    }
    

提交回复
热议问题