我正在尝试检查 Native Client文件系统中是否存在目录,但找不到任何功能来执行此操作。我尝试为目录创建一个PPB_FileRef
,然后使用打开该目录,PPB_FileIO::Open
然后调用PPB_FileIO::Query
但PPB_FileIO::Open
返回PP_ERROR_NOTAFILE
,然后第二次调用失败。
这是我一直在尝试的代码,为简洁起见,省略了一些初始化。
PP_Instance instance; // initialised elsewhere
PPB_FileRef *fileRefInterface; // initialised elsewhere
PPB_FileIO *fileIOInterface; // initialised elsewhere
PP_Resource fileSystemResource; // initialised elsewhere
PP_Resource fileRefResource = fileRefInterface->Create(
fileSystemResource,
"/directory");
PP_Resource fileIOResource = fileIOInterface->Create(instance);
// This call is returning PP_ERROR_NOTAFILE
//
int32_t result = fileIOInterface->Open(
fileIOResource,
fileRefResource,
PP_FILEOPENFLAG_READ,
PP_BlockUntilComplete()); // this is being called from a background thread.
if (result != PP_OK)
{
return false;
}
PP_FileInfo info;
result = fileIOInterface->Query(fileIOResource, &info, PP_BlockUntilComplete());
if (result != PP_OK)
{
return info.type == PP_FILETYPE_DIRECTORY;
}
return false;
PP_ERROR_NOTAFILE
fromPPB_FileIO::Open
的返回值是否PPB_FileRef
足以让我告诉它是一个目录,还是我应该使用另一种更好的方法?
谢谢,詹姆斯