gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:53:33 31 4
gpt4 key购买 nike

我正在使用 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];

最佳答案

我正在使用此代码:

从 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

关于ios - NSTask 不适用于具有特殊字符的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198674/

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