IOS获取文件属性。(包括创建日期)
FileInfo *fileInfo = [[FileInfo alloc] init]; fileInfo.name = fileName; fileInfo.path = [rootPath stringByAppendingPathComponent:fileName]; //判断是文件夹还是文档 BOOL isDir = YES; [fileManager fileExistsAtPath:fileInfo.path isDirectory:&isDir]; if (isDir) { //文件夹 fileInfo.isDir = YES; fileInfo.isLock = NO; }else{ //文档 } NSError *error = nil; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fileInfo.path error:&error]; if (fileAttributes) { NSNumber *fileSize; NSString *fileOwner, *creationDate; NSDate *fileModDate; //文件大小 if ((fileSize = [fileAttributes objectForKey:NSFileSize])) { NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]); if (!fileInfo.isDir) { fileInfo.size = [fileSize intValue]; } } //文件创建日期 if ((creationDate = [fileAttributes objectForKey:NSFileCreationDate])) { NSLog(@"File creationDate: %@\n", creationDate); fileInfo.date = creationDate; } //文件所有者 if ((fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName])) { NSLog(@"Owner: %@\n", fileOwner); } //文件修改日期 if ((fileModDate = [fileAttributes objectForKey:NSFileModificationDate])) { NSLog(@"Modification date: %@\n", fileModDate); } }