macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

directoryContentsAtPath:

pathで指定したディレクトリのファイル名の一覧を返します
-(NSArray *)directoryContentsAtPath:(NSString *)path:

解説

pathで指定したディレクトリ(フォルダ)のファイル名の一覧を返します。
エラーが起こればnilを返します。
pathで指定したディレクトリ(フォルダ)がなければnilを返します。
pathで指定したディレクトリ(フォルダ)の中身が無ければ、空の配列を返します。
指定したディレクトリ(フォルダ)の中だけを探して、含まれているディレクトリ(フォルダ)の中までは探しません。
シンボリックリンクエイリアスもそのファイルを返して、元ファイルは返しません。

返り値

( NSArray * )

ファイル名の一覧の配列

引数

( NSString * )path

ディレクトリのパス

クラス

NSFileManager

Instance Methods

使用可能

10.0

参照

- currentDirectoryPath
- fileExistsAtPath:isDirectory:
- enumeratorAtPath:
- subpathsAtPath:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSString *str = @"~/";
NSFileManager *myFile = [ NSFileManager defaultManager];
[myFile changeCurrentDirectoryPath:[str stringByExpandingTildeInPath]];

NSLog([[myFile directoryContentsAtPath:@"Documents"] description]);
}

@end