只是好奇,如果這是做到這一點,只是想確保它不漏水,但我會認爲我只修改字符串內容。這是在循環中創建/銷燬字符串的正確方法嗎?
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