object-c获取文件各项属性方法

获取文件各项属性方法   

 

刚总结了下:

 

-(NSData *)applicationDataFromFile:(NSString *)fileName

{

    NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString *documentsDirectory =[paths objectAtIndex:0];

    NSString *appFile =[documentsDirectory stringByAppendingPathComponent:fileName];

    NSData *data =[[[NSData alloc]initWithContentsOfFile:appFile]autorelease];

    return data;

}

-(void)getFileAttributes

{

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *path = @"/1ct.rtf";

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES];

    NSLog(@"@@");

if (fileAttributes != nil) {

    NSNumber *fileSize;

    NSString *fileOwner, *creationDate;

    NSDate *fileModDate;

    //NSString *NSFileCreationDate

    if (fileSize = [fileAttributes objectForKey:NSFileSize]) {

        NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);

    }

    if (creationDate = [fileAttributes objectForKey:NSFileCreationDate]) {

        NSLog(@"File creationDate: %@\n", creationDate);

        //textField.text=NSFileCreationDate;

    }

    if (fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName]) {

        NSLog(@"Owner: %@\n", fileOwner);

    }

    if (fileModDate = [fileAttributes objectForKey:NSFileModificationDate]) {

        NSLog(@"Modification date: %@\n", fileModDate);

    }

 }

else {

    NSLog(@"Path (%@) is invalid.", path);

   }

}

 

posted on 2011-06-20 18:20  风乔  阅读(378)  评论(0编辑  收藏  举报

导航