• iOS对于目录的操作


    原文地址:iOS对于目录的操作作者:angellixf
    iOS可操作目录有两种:Documents下与Caches下, 如图:
    [转载]iOS对于目录的操作 - 102212335 - 缘的博客

    [转载]iOS对于目录的操作 - 102212335 - 缘的博客

     
    1、创建目录createDirectoryAtPath:withIntermediateDirectories:attributes:error:

    NSFileManager * fileManager = nil;

    NSArray *paths = nil;

    NSString *documentsDirectory = nil;

    NSString * folerName = @"Photos";

    NSString * fileName = @"myphoto.png";

    NSString  * filePath = nil;

    UIImage *photoimage = nil;

    NSData * imageData = nil;

     

    //Documents:

     

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

     

    //Caches:

    paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

     

    documentsDirectory = [[paths objectAtIndex:0stringByAppendingPathComponent:folerName];

    fileManager = [[NSFileManager alloc]init];

    [fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:error];

     

     

     

     

     

    2、创建目录并在目录中存储对象createFileAtPath: contents: attributes

     

    filePath = [documentsDirectory stringByAppendingPathComponent:filename];

     

    if((![fileManager fileExistsAtPath: fullPathToFile])) 

         {

    photoimage = [[UIImage allocimageNamed:@"photo.png"];

    imageData = UIImagePNGRepresentation(photoimage);

    [fileManager createFileAtPath:filePath contents: imageData attributes:nil];

        }

    [photoimage release];

    [fileManager release];

     

     

    3、删除目录中指定文件

     

    NSString * filePath = [documentsDirectory stringByAppendingPathComponent: fileName];

    [filemanager removeItemAtPath: filePath error:NULL];
  • 相关阅读:
    Python运算符及逻辑运算
    Python编码、流程控制、格式化输出
    Docker私有仓库Harbor部署与使用
    react
    理事会
    关于elementui form表单过长,看不到未填项
    js
    vue 父子传值
    养生
    html知识点
  • 原文地址:https://www.cnblogs.com/xiaonanxia/p/2729239.html
Copyright © 2020-2023  润新知