2013-10-25 28 views
1

我在公司中處理了很多Lotus Notes。我在C#中編寫了一個很棒的應用程序,用於從用戶的Lotus Notes目錄複製特定的文件。現在我想在Objective C中爲OSX編寫該應用程序。我有一些不同的文件需要從〜/ Library/Application Support/Lotus Notes Data /中複製。從應用程序支持中複製文件

我在運行測試以複製單個文件時遇到了管理員問題。什麼是最好的/最簡單的方式(我是一個初學者)提示用戶輸入管理員憑證並使用新獲得的權限執行文件複製代碼?

我曾嘗試實現我在網上找到的BLAuthentication類,但它不會編譯。我目前無法訪問我的工作計算機以發佈代碼。

回答

0

嘗試這樣如下: -

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]); 
} 
+0

此外,如果要列舉了多個文件,然後按照此連結http:

您可以通過在你的包中添加以上腳本「.scpt」文件,並使用下面的代碼調用腳本的蘋果/ /stackoverflow.com/questions/18683345/cycle-through-a-directory-and-get-paths-of-all-the-files-and-folders/18688333#18688333 –

+0

Hussain,完美的工作。非常感謝你!你能解釋它是如何從/ Library/vs CopyItemAtPath中複製的? – Lgwells1

+0

我沒有得到你的問題?你想知道copyItemAtPath是如何工作的? –

0

使用Apple腳本與特權訪問複製文件。

do shell script "cp source_path destination_path" with administrator privileges 

其中,源路徑是要複製的文件的路徑。

- (void) runEmbeddedScriptFile: (NSString*)fileName 
{ 
    NSString* path = [[NSBundle bundleForClass:[self class]] pathForResource:fileName ofType:@"scpt"]; 
    NSURL* url = [NSURL fileURLWithPath:path]; 
    NSDictionary* errors = [NSDictionary dictionary]; 
    NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors]; 
    [appleScript executeAndReturnError:nil]; 
    [appleScript release]; 
} 
+0

這將提示來自用戶的密碼請求。 – Neha

+0

腳本在腳本編輯器中工作,但您的代碼不會運行腳本。 –

+0

腳本在腳本編輯器中工作,但您的代碼不運行腳本。因爲URL改變 見路徑= /Users/priyadarshanjoshi/Library/Developer/Xcode/DerivedData/PMB-cxezmjfqztaqoyaedjsgubffmbso/Build/Products/Debug/PMB.app/Contents/Resources/CopyAppleScript.scpt 和URL conversin後is = file:///Users/priyadarshanjoshi/Library/Developer/Xcode/DerivedData/PMB-cxezmjfqztaqoyaedjsgubffmbso/Build/Products/Debug/PMB.app/Contents/Resources/CopyAppleScript.scpt 但是在執行腳本文件之後沒有複製並沒有顯示任何錯誤。 –

相關問題