• Object-C,遍历目录


    最近武汉连续下雨很多天,降温了2次,温度一下子由28度到14度,再到8度,手太冷了。

    加上最近发生了一些比较棘手的家庭琐事,最近没心情继续学习Object-C

    后来,我想明白了,心情不好的时候,还是应该坚持学习。

    郁郁寡欢,于事无补,该干嘛干嘛去~

    不开心的事情,总会过去的。等过去之后,该做的事情总是要继续做的。

    因为不开心,浪费不少大好时间,才是雪上加霜的。

    计划20152016年,初步掌握iOS开发。

    一个人可以独自开发iOS应用,看得懂、能够维护别人已经写好的APP

    Android也是必须同时深入学习的。

    我现在的初步感觉是,Android上手容易,但是因为开源可以有更多内容需要学习。

    Object-CiOS开发,上手男很多,但是要学习的内容会少很多。


    Mac,这么小的Mac,开发打字效率好低啊,让人着急额~最近搞得多了,稍微快了一些。

    //
    //  main.m
    //  FilePath
    //
    //  Created by fansunion on 15/11/29.
    //  Copyright (c) 2015年 demo. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    //enumeratorAtPath 遍历目录,如果目录下有目录,递归遍历
    //contentsOfDirectoryAtPath 只遍历目录
    //比较尴尬的是,“当前工作目录”下,只有1个文件,有点奇怪
    //所以最后手动,遍历“/Users/fansunion”/下的文件,只能简单地看看这个目录下的文件(目录)列表
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSString *currentPath;
            NSString *tempPath;
            NSFileManager *fm;
            NSDirectoryEnumerator *dirEnum;
            NSArray *dirArray;
            
            //文件管理器的实例
            fm = [NSFileManager defaultManager];
            //获取当前工作目录的路径
            currentPath = [fm currentDirectoryPath];
            NSLog(@"The Path is %@!",currentPath);
            //枚举目录
            dirEnum =[fm enumeratorAtPath:currentPath];
    
            while((tempPath=[dirEnum nextObject])!= nil){
                NSLog(@"%@",tempPath);
            }
            
            //另外一种枚举目录的方法
            dirArray= [fm contentsOfDirectoryAtPath:currentPath error:NULL];
            NSLog(@"%@",dirArray);
            for(tempPath in dirArray){
                 NSLog(@"%@",tempPath);
            }
            
            dirArray =[fm contentsOfDirectoryAtPath:@"/Users/fansunion" error:NULL];
            NSLog(@"%@",dirArray);
    
        }
        return 0;
    }

    程序输出

    2015-11-29 13:02:49.528 FilePath[2750:159478] The Path is /Users/fansunion/Library/Developer/Xcode/DerivedData/FilePath-dfjiajapcipfrbcbfjmxijqhscws/Build/Products/Debug!

    2015-11-29 13:02:49.534 FilePath[2750:159478] FilePath

    2015-11-29 13:02:49.534 FilePath[2750:159478] (

        FilePath

    )

    2015-11-29 13:02:49.534 FilePath[2750:159478] FilePath

    2015-11-29 13:02:49.535 FilePath[2750:159478] (

        ".bash_history",

        ".CFUserTextEncoding",

        ".DS_Store",

        ".ssh",

        ".subversion",

        ".Trash",

        Desktop,

        Documents,

        Downloads,

        Library,

        Movies,

        Music,

        Pictures,

        Public

    )

    Program ended with exit code: 0



  • 相关阅读:
    结构体数组
    怎样在Linux下通过ldapsearch查询活动文件夹的内容
    Phalcon之 表单(Forms)
    Java模式(适配器模式)
    人类智商一般在多少左右?爱因斯坦的智商是多少?
    SQL中declare申明变量
    apache2.2 虚拟主机配置
    项目实施阶段该做好哪些方面的工作
    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之全然具体解释
    ExtJs自学教程(1):一切从API開始
  • 原文地址:https://www.cnblogs.com/qitian1/p/6462568.html
Copyright © 2020-2023  润新知