Objective-C Foundation 框架 Example :Looking for Files 查找文件_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Objective-C Foundation 框架 Example :Looking for Files 查找文件

Objective-C Foundation 框架 Example :Looking for Files 查找文件

 2015/5/5 21:09:03  巴山夜雨1989  程序员俱乐部  我要评论(0)
  • 摘要:Objective-CFoundation框架Example:LookingforFiles查找文件NSFileManager.TheNSFileManagerclassletsyoudostuffwiththefilesystem,likecreatedirectories,removefiles,movefilesaround,andgetinformationaboutfiles.NSFileManager:让你处理一些文件系统的事情,比如创建目录,移除文件,移动文件,获取文件的信息
  • 标签:Foundation file files for 文件 查找

Objective-C Foundation 框架    Example :Looking for Files  查找文件

NSFileManager. The NSFileManager class lets you do stuff with the file system, like create directories, remove files, move files around, and get information about files.

 NSFileManager:让你处理一些文件系统的事情,比如创建目录,移除文件,移动文件,获取文件的信息。

 

 

//

//  main.m

//  Helloworld

//

//  Created by kfx on 15-5-4.

//  Copyright (c) 2015年 com.MySuperCompany. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        NSFileManager *manager;

        manager = [NSFileManager defaultManager];

          

        NSString *home;

        home = [@"~" stringByExpandingTildeInPath];

          

        NSDirectoryEnumerator *direnum;//目录枚举

        direnum = [manager enumeratorAtPath:home];

          

        NSMutableArray *files;

        files = [NSMutableArray arrayWithCapacity:42];

          

        NSString *filename;

        while (filename = [direnum nextObject])

        {

            if ([[filename pathExtension] isEqualTo: @"jpg"]) {

                [files addObject: filename];

            } }

        NSEnumerator *fileenum;

        fileenum = [files objectEnumerator];

        while (filename = [fileenum nextObject])

        {

            NSLog (@"%@", filename);

        }    }

    return 0;

}

 

  

 

    return 0;

}

 

 

 

where in the file system to start looking at files?

Starting from the top level of your hard drive could take a long time, so let's just look in your home directory.

在home目录下开始。

Luckily, Unix (and OS X) has a shorthand character for the home directory, which is ~ (also known as the tilde).

unix 和os x 有一个简单地字符串代表home 目录。 

发表评论
用户名: 匿名