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

标签 cocoa api macos

我正在尝试替换已弃用的 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/

相关文章:

cocoa - 多个 View 和 Controller 的 MVC 类组织是什么样的?

objective-c - 在 Objective-C 中检测按键两次

Swift 我可以将 NSTextview 分配为尚未创建的全局吗?

javascript - Axios:无法使用基本身份验证调用 API

cocoa - 将 NSTreeController 与 MagicalRecord 绑定(bind)

api - 不是有效的 base64 图像

ruby-on-rails - Rails 的 Mailchimp API - list.subscribe( :double_optin => false) not working

iphone - 核心蓝牙: Cannot get iPhone (the central) and Mac (the peripheral) to pair

python - MySQL-python 安装 - 错误的架构 - MacOS

objective-c - 在 Cocoa 中创建单选按钮矩阵