我試着用NSFileManager的attributesOfItemAtPath。它適用於文件,但不適用於文件夾。雖然在Apple's documentation,他們聲稱它應該在文件或文件夾上工作。但是,如果我在文件夾中調用此函數,我所得到的值都是零值。有沒有辦法在Cocoa中獲取文件夾的創建日期?
碼我用:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDictionary *folderAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:somePath error:nil];
NSLog(@"Creation date: %@", [dateFormatter stringFromDate:[folderAttributes objectForKey:NSFileCreationDate]]);
輸出總是空給我。我的 「somePath」 是一個NSString,像這樣的格式:
file://localhost/Users/username/...
的思考?謝謝!
謝謝!特別是對於錯誤部分! –