只是好奇,如果这是做到这一点,只是想确保它不漏水,但我会认为我只修改字符串内容。这是在循环中创建/销毁字符串的正确方法吗?
NSMutableString *newPath = [[NSMutableString alloc] init];
for(fileName in [manager enumeratorAtPath:rootPath]){
if ([[fileName pathExtension] isEqual:@"exr"]) {
[fileArray addObject:fileName];
// THIS BIT
[newPath setString:rootPath];
[newPath appendString:@"/"];
[newPath appendString:fileName];
// HERE
attrDir = [manager attributesOfItemAtPath:newPath error:&myError];
fileSize = [attrDir objectForKey: @"NSFileSize"];
NSLog(@"File: /%@ Size: %@", fileName, fileSize);
}
}
[newPath release];
加里
嗯我尝试添加[NEWPATH stringByAppendingPathComponent:@ “/”];要测试添加“/”的结尾,但我似乎无法得到它的工作... – fuzzygoat 2009-09-28 21:22:46
stringByAppendingPathComponent避免你必须知道分隔符。我已经更新了答案以反映使用情况。 – nall 2009-09-28 21:39:56
谢谢,那它怎么知道要添加什么? – fuzzygoat 2009-09-28 21:44:41