zoukankan      html  css  js  c++  java
  • objc iOS 开发,取得当前目录下后缀名这.png的文件目录。

    #import <UIKit/UIKit.h>
    
    @interface imageSet : UIViewController
    {
        NSMutableArray *filePathArray;
        NSFileManager *localFileManager;
    }
    
    
        NSDirectoryEnumerator *myDirectoryEnumerator;
        NSFileManager *myFileManager=[NSFileManager defaultManager];
    
        myDirectoryEnumerator=[myFileManager enumeratorAtPath:[[NSBundle mainBundle] bundlePath]];
        
        NSString *docPath;
        docPath = [self documentsPath];   //得到文件的路径
        NSLog(@"%@", docPath);     
        filePathArray = [[NSMutableArray alloc]init];   //用来存目录名字的数组 
        localFileManager=[[NSFileManager alloc] init];  //用于获取文件列表
       
        NSString *file;
        
        while((file=[myDirectoryEnumerator nextObject]))     //遍历当前目录
        {
            if([[file pathExtension] isEqualToString:@"png"])   //取得后缀名这.png的文件名
            {
                [filePathArray addObject:[docPath stringByAppendingPathComponent:file]]; //存到数组
                NSLog(@"%@",file);
                //NSLog(@"%@",filePathArray);
            }
            
        }
        
    
    
    
    //获得项目中当前文件名里的内容
    -(NSString *)bundlePath:(NSString *)fileName {
        return [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:fileName];
        
        //[NSBundle mainBundle] resourcePath
    }
    
    
    //获得项目中同一级文件中目录名字
    -(NSString *)documentsPath:(NSString *)fileName {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        return [documentsDirectory stringByAppendingPathComponent:fileName];
    }
    
    -(NSString *)documentsPath {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        return documentsDirectory;
    }
  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/qingjoin/p/2574882.html
Copyright © 2011-2022 走看看