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 目录。

Objective-C Foundation 框架 Example :Looking for Files 查找文件的更多相关文章

  1. Objective - c Foundation 框架详解2

    Objective - c  Foundation 框架详解2 Collection Agency Cocoa provides a number of collection classes such ...

  2. Foundation 框架 NSFileManager,NSData 简单的文件操作

    一.简单展示NSFileManager的使用 #import <Foundation/Foundation.h> int main(int argc, const char * argv[ ...

  3. Objective-C( Foundation框架 一 常见的结构体)

    常见的结构体 (NSPoint,CGPoint).(NSRange,CGRange).(NSSize,CGSize) 苹果官方推荐使用CG开头的结构体 NSRange是Foundation框架中常见的 ...

  4. Objective-C语言Foundation框架

    Mac OS X开发会使用Cocoa框架,它是一种支持应用程序提供丰富用户体验的框架,它实际上由:Foundation和Application Kit(AppKit)框架组成.iOS开发,会使用Coc ...

  5. iOS Foundation 框架概述文档:常量、数据类型、框架、函数、公布声明

    iOS Foundation 框架概述文档:常量.数据类型.框架.函数.公布声明 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业 ...

  6. Foundation框架下的常用类:NSNumber、NSDate、NSCalendar、NSDateFormatter、NSNull、NSKeyedArchiver

    ========================== Foundation框架下的常用类 ========================== 一.[NSNumber] [注]像int.float.c ...

  7. iOS开发系列—Objective-C之Foundation框架

    概述 我们前面的章节中就一直新建Cocoa Class,那么Cocoa到底是什么,它和我们前面以及后面要讲的内容到底有什么关系呢?Objective-C开发中经常用到NSObject,那么这个对象到底 ...

  8. Foundation框架-NSString和NSMutableString

    可变与不可变的字符串 --1-- Foundation框架介绍 1.1 框架介绍 --2-- NSString 2.1 NSString介绍及使用 2.2 NSString创建方式  2.3 从文件中 ...

  9. Core Foundation框架

    转载自:http://blog.csdn.net/weiwangchao_/article/details/7744972 Core Foundation框架 (CoreFoundation.fram ...

随机推荐

  1. 【MongoDB】The description of procedure in MongoDB

    In this blog the procedure of mongodb will be described in details. It is known that mongodb has pro ...

  2. go内存泄露case

    用go写了一个守护进程程序:用于检測redis的存活状态并将结果写到zookeeper中,部署到redis机器上.对于每一个redis实例会有一个goroutine每隔固定时间去检測其状态,由主gor ...

  3. Lightoj 1023 - Discovering Permutations

    1023 - Discovering Permutations    PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory L ...

  4. linux文件读写 文件锁、select、poll【转】

    本文转载自:http://blog.csdn.net/fansongy/article/details/6853395 一.文件锁 文件锁用于多个用户共同使用或操作同一个文件.有读锁的时候可以再加读锁 ...

  5. POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包

    题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 655 ...

  6. Java对象与对象引用变量的理解

    Java对象及对象引用 首先定义一个简单的类: class User{ int userId; String userName; } 我们在创建对象时,通常会写: User user = new Us ...

  7. 并不对劲的bzoj2820:p2257:YY的GCD

    题目大意 \(t\)(\(t\leq10^4\))组数据,给定\(n,m\)(\(n,m\leq10^6\))求 \[\sum_{x=1}^{n}\sum_{y=1}^{m}[gcd(x,y)=1]\ ...

  8. 【HAOI 2008】 硬币购物

    [题目链接] 点击打开链接 [算法] 此题是一道好题! 首先,我们发现 : 付款方法数 = 不受限制的方法数 - 受限制的方法数 那么,我们怎么求呢? 我们用dp求出不受限制的方法数(f[i]表示买i ...

  9. 从0开始学习Hadoop(1) 环境准备 Win7环境+VirtureBox+Ubuntu

    虚拟机:VirtureBox 3.18 下载地址: https://www.virtualbox.org/ 操作系统:Ubuntu  版本:ubuntu-15.04-desktop-amd64.iso ...

  10. (转)ASP.NET 4.0 尚未在 Web 服务器上注册

    安装vs2010的时候忘记先安装IIS7了,导致出现了这个问题.经过网络查询发现解决方法如下: 运行:cmd命令,进入命令管理器, 输入:cd C:\\WINDOWS\\Microsoft.NET\\ ...