1

ユーザーがここに投稿したコードを少し使用して、進行状況バーを使用してファイルをコピーするように設定を変更しました (Cocoa からは私のガールフレンドですhttp://www.cimgf.com/2008/05/03/cocoa-チュートリアル ファイル コピー ウィズ プログレス インジケーター/ )。

非推奨の方法の使用のいくつかを修正しようとしましたが、その過程でファイルサイズの検出が壊れました。昨日は一日のほとんどを費やして、それを修正するためにさまざまなことを試みましたが、運がありませんでした. sourceFilePath は NSTextField から取得されることにも注意してください。

ファイルが存在しないというエラーメッセージが表示されることは知っていますが、確かに存在します。そのパスにはシンボリック リンクが含まれていないため、NSString メソッド stringByResolvingSymlinksInPath を使用したことを確認します。ここで何がうまくいかないのですか?コードと、表示されるエラー メッセージを次に示します。

- (IBAction)startCopy:(id)sender;
{
NSError *attributeserror = nil;

NSString *accountsourcestring = [sourceFilePath stringValue];
NSString *accountsourcestringpath =[accountsourcestring stringByStandardizingPath];

// Use the NSFileManager to obtain the size of our source file in bytes.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *sourceAttributes = [fileManager     attributesOfItemAtPath:accountsourcestringpath error:&attributeserror];
NSNumber *sourceFileSize= [sourceAttributes objectForKey:NSFileSize];
long long fileSize = [sourceFileSize longLongValue];

NSLog(@"Filesize = %lld", fileSize);
NSLog(@"sourcefilepath: %@", accountsourcestring);

if ((sourceFileSize = [sourceAttributes objectForKey:NSFileSize]) )
{
    // Set the max value to our source file size
    [progressIndicator setMaxValue:(double)[sourceFileSize unsignedLongLongValue]];
}
    else
{
    // Couldn't get the file size so we need to bail.
    NSLog(@"Unable to obtain size of file being copied. Error %@ Source file size: %@,   sourceAttributes: %@", attributeserror, sourceFileSize, sourceAttributes);
    return;
}

そして、コンソールに記録されたエラーメッセージは次のとおりです。

2012-09-01 11:23:07.061 Copy File[1004:303] Filesize = 0
2012-09-01 11:23:07.062 Copy File[1004:303] sourcefilepath:     file://localhost/Users/daniel/Lion%20plists/
2012-09-01 11:23:07.072 Copy File[1004:303] Unable to obtain size of file being copied.    Error Error Domain=NSCocoaErrorDomain Code=260 "The file “Lion%20plists” couldn’t be opened   because there is no such file." UserInfo=0x100173770   {NSFilePath=file:/localhost/Users/daniel/Lion%20plists, NSUnderlyingError=0x100140240 "The   operation couldn’t be completed. No such file or directory"} Source file size: (null),   sourceAttributes: (null)
4

0 に答える 0