Objective-C Foundation 架構 Example :Looking for Files 尋找檔案

來源:互聯網
上載者:User

標籤:

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 尋找檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.