Objective-C FoundationフレームワークExample:Looking for Filesファイルの検索
2022 ワード
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:ディレクトリの作成、ファイルの削除、ファイルの移動、ファイルの情報の取得など、ファイルシステムの処理を行います.
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.
ホームディレクトリの下で開始します.
Luckily, Unix (and OS X) has a shorthand character for the home directory, which is ~ (also known as the tilde).
Unixとosxには、ホームディレクトリを表す簡単な文字列があります.
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.
ホームディレクトリの下で開始します.
Luckily, Unix (and OS X) has a shorthand character for the home directory, which is ~ (also known as the tilde).
Unixとosxには、ホームディレクトリを表す簡単な文字列があります.