gpt4 book ai didi

cocoa - CoreService 框架有关于 PBFSCopyFileSync 的详细文档或示例代码吗?

转载 作者:行者123 更新时间:2023-12-03 16:59:52 24 4
gpt4 key购买 nike

我正在尝试替换已弃用的 API PBHCopyFileSyncPBFSCopyFileSync正如 Files.h 中的推荐 header 。

令人惊讶的是,Apple 对于这个新 API 只说了几行:

PBFSCopyFileSync
Duplicates a file and optionally renames it.

OSStatus PBFSCopyFileSync (
FSRefParamPtr paramBlock
);
Availability
Available in Mac OS X v10.5 and later.
Declared In
Files.h

而且我找不到有关如何使用此功能的更多信息。

特别是参数FSRefParamPtr应该填写什么?我尝试了下面的代码,但始终收到 -50 的错误。

paramErr     -50    
Invalid value passed in a parameter. Your application
passed an invalid parameter for dialog options.

这是代码:

OSStatus res = noErr;

FSRefParam param;

FSRef srcFile, dstDir, newFile;

const char *src = "$PATH_TO_A_EXISTING_FILE";
const char *dst = "/tmp";

res = FSPathMakeRef((const UInt8 *)src, &srcFile, NULL);
assert(res == noErr);

res = FSPathMakeRef((const UInt8 *)dst, &dstDir, NULL);
assert(res == noErr);

memset(&param, 0, sizeof(FSRefParam));
param.ioCompletion = NULL;
param.ref = &srcFile;
param.parentRef = &dstDir;
param.newRef = &newFile;

res = PBFSCopyFileSync(&param);

if (res == noErr) {
printf("SUCCESS!!!\n");
} else {
printf("FAILED!!! %d\n", res);
}

那么,有谁知道有关此 API 的一些详细文档或示例代码吗?或者是否有更流行/有记录的 C++ API 用于复制文件?

谢谢。

最佳答案

Quinn “The Eskimo!” says:

Always use FSCopyObjectSync. PBFSCopyFileSync/PBHCopyFileSync are low-level routines that are exported for legacy reasons. FSCopyObjectSync is a proper API that takes care of all of the nittygritty details of copying.

Notably, both PBFSCopyFileSync and PBHCopyFileSync are parameter block routines, with no nice wrappers. You should consider that a hint (-:

关于cocoa - CoreService 框架有关于 PBFSCopyFileSync 的详细文档或示例代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com