gpt4 book ai didi

cocoa - 将文件复制到应用程序支持或从应用程序支持复制文件

转载 作者:行者123 更新时间:2023-12-03 17:22:24 25 4
gpt4 key购买 nike

我在公司里经常与 Lotus Notes 打交道。我用 C# 编写了一个很棒的应用程序,用于将特定文件复制到用户的 Lotus Notes 目录中或从用户的 Lotus Notes 目录中复制特定文件。现在我想在 Objective C 中为 OSX 编写该应用程序。我有一些不同的文件需要从 ~/Library/Application Support/Lotus Notes Data/复制。

当我运行测试来复制单个文件时,我遇到了管理问题。提示用户输入管理员凭据并使用新获得的权限执行文件复制代码的最佳/最简单方法是什么(我是初学者)?

我确实尝试实现在网上找到的 BLAuthentication 类,但它无法编译。我目前无法访问我的工作计算机来发布代码。

最佳答案

尝试如下:-

NSString *path=[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)lastObject];
NSString *testUrl =[path stringByAppendingPathComponent:@"/LotusNotesData/source.rtf"];
//
if ([[NSFileManager defaultManager]fileExistsAtPath:testUrl]) {
NSLog(@"yes");
}
//Below destination is folder name which should be exist on your machine or else you can create programmatically as well
NSString *testUrl2 = @"/Users/home/Documents/destination";

NSLog(@"%@",testUrl);
NSLog(@"%@",testUrl2);
NSError *err=nil;

//Now we are copying the souce path to destination folder with appending file name (it can be any your name becuase file manager copy source file contents to your destination file contents)
//Here given file name is a source.rtf where you can give any your name. Also this is for copying source contents to destination contents

NSFileManager *fm=[NSFileManager defaultManager];
if ([fm copyItemAtPath:testUrl toPath:[testUrl2 stringByAppendingPathComponent:@"source.rtf"] error:&err])
{
NSLog(@"success");
}
else
{
NSLog(@"%@",[err localizedDescription]);
}

关于cocoa - 将文件复制到应用程序支持或从应用程序支持复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19580681/

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