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

来源:互联网 发布:ios手游网络加速器 编辑:程序博客网 时间:2024/05/20 11:24
  1. NSString *strPath =[[NSBundle mainBundle] pathForResource:@"lomo.jpg" ofType:nil];  
  2.     NSLog(@"path:%@", strPath);  
  3.     NSFileManager *fileManager = [NSFileManager defaultManager];  
  4.     NSString *path = strPath;//@"/tmp/List";  
  5.     NSError *error = nil;  
  6.     NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:path error:&error];  
  7.       
  8.     if (fileAttributes != nil) {  
  9.         NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];  
  10.         NSString *fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName];  
  11.         NSDate *fileModDate = [fileAttributes objectForKey:NSFileModificationDate];  
  12.         NSDate *fileCreateDate = [fileAttributes objectForKey:NSFileCreationDate];  
  13.         if (fileSize) {  
  14.             NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);  
  15.         }  
  16.         if (fileOwner) {  
  17.             NSLog(@"Owner: %@\n", fileOwner);  
  18.         }  
  19.         if (fileModDate) {  
  20.             NSLog(@"Modification date: %@\n", fileModDate);  
  21.         }  
  22.         if (fileCreateDate) {  
  23.             NSLog(@"create date:%@\n", fileModDate);  
  24.         }  
  25.     }  
  26.     else {  
  27.         NSLog(@"Path (%@) is invalid.", path);  
  28.     }  
0 0
原创粉丝点击