NSTask不适用于具有特殊字符的文件路径

时间:2014-06-13 06:00:46

标签: ios objective-c macos cocoa-touch cocoa

我正在使用NStask来获取文件夹大小。它适用于普通文件路径,如home / ABC / Users / testUser / Documents。但它没有显示文件路径的任何输出,如home / ABC / Users / testUser /Ω≈ç∂√√√∂ƒ∂。但是我在终端上获得了相同文件路径的正确输出。有什么建议吗?

    NSString* userName = @"test123_test123";
    NSString* password = @"test";
    NSString* serverIP = @"200.144.172.210";
    NSString* sizeFolderPath = [[NSBundle mainBundle] pathForResource:@"demoUtilities" ofType:nil];

    NSString* xml= @"--test";
    NSString* passwordArg = [NSString stringWithFormat:@"--pwd-=%@",password];

    NSString *filePath = @"UsersMac/Users/test/Ω≈ç∂√√√∂ƒ∂";
    NSString* address = [NSString stringWithFormat:@"%@@%@::home/%@", userName,   serverIP,filePath];
    NSArray* arguments = [NSMutableArray arrayWithObjects:xml,passwordArg,address,nil];

    TestCommandExcecuter *cmExec = [[TestCommandExcecuter alloc]init];
    [cmExec setCommandString:sizeFolderPath];
    [cmExec setCommandArguments:arguments];

1 个答案:

答案 0 :(得分:1)

我正在使用此代码:

从2.0

中删除
 NSDictionary *fileDictionary = [[NSFileManager defaultManager]   
                                    fileAttributesAtPath:filePath traverseLink:YES];

long long size = [fileDictionary fileSize];
 NSLog(@"size :: %lld",size);

最新消息:

 NSDictionary *fileDictionary = [[NSFileManager defaultManager] 
                                     attributesOfItemAtPath:filePath error:nil];

long long size = [fileDictionary fileSize];
NSLog(@"size :: %lld",size);

以下是参考链接:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/attributesOfItemAtPath%3aerror%3a