• objectc获取文件各项属性方法


    获取文件各项属性方法   

    刚总结了下:

    -(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);

       }

    }

  • 相关阅读:
    [算法分析]计数排序
    [置顶] 基于stm32f103zet6之UC/OS_II的学习1(初步移植OS点灯大法)
    IOS开发(59)之Block Object的调用
    【译】测试员,敢问路在何方?来自微软工程师
    各种字符串hash
    hdu 2579 BFS
    qq相册
    程序人生之我们的故事:十年如歌(9)
    关联模型和无限极分类
    十大技巧破解电话面试
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175666.html
Copyright © 2020-2023  润新知