查看IOS沙盒中文件的属性(修改日期,创建日期,大小等)

NSString *strPath =[[NSBundle mainBundle] pathForResource:@"lomo.jpg" ofType:nil];
    NSLog(@"path:%@", strPath);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = strPath;//@"/tmp/List";
    NSError *error = nil;
    NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:&error];
    
    if (fileAttributes != nil) {
        NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
        NSString *fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName];
        NSDate *fileModDate = [fileAttributes objectForKey:NSFileModificationDate];
        NSDate *fileCreateDate = [fileAttributes objectForKey:NSFileCreationDate];
        if (fileSize) {
            NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);
        }
        if (fileOwner) {
            NSLog(@"Owner: %@\n", fileOwner);
        }
        if (fileModDate) {
            NSLog(@"Modification date: %@\n", fileModDate);
        }
        if (fileCreateDate) {
            NSLog(@"create date:%@\n", fileModDate);
        }
    }
    else {
        NSLog(@"Path (%@) is invalid.", path);
    }


你可能感兴趣的:(查看IOS沙盒中文件的属性(修改日期,创建日期,大小等))