Instance Method インスタンスメソッド

enumeratorAtPath:

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path. 指定されたパスでのディレクトリの深い列挙を実行するために使用できるディレクトリ列挙子オブジェクトを返します。

Declaration 宣言

- (NSDirectoryEnumerator<NSString *> *)enumeratorAtPath:(NSString *)path;

Parameters パラメータ

path

The path of the directory to enumerate. 列挙するディレクトリのパス。

Return Value 戻り値

A NSDirectoryEnumerator object that enumerates the contents of the directory at path. NSDirectoryEnumeratorオブジェクト、それはpathでのディレクトリの内容を列挙します。

If path is a filename, the method returns an enumerator object that enumerates no files—the first call to nextObject will return nil. pathがファイル名ならば、メソッドは全くファイルを列挙しない列挙子オブジェクトを返します — nextObjectに対する最初の呼び出しはnilを返すでしょう。

Discussion 議論

Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory. 列挙は深くまで達することから — すなわち、それは下位ディレクトリの内容を一覧にします — この列挙子オブジェクトは多数のファイルシステム下位ツリーを伴うさまざまな動作を実行するのに有用です。このメソッドは、辿っていく過程において出くわすシンボリックリンクそれらを解決しませんし、それらがディレクトリを指すならばそれらを通して再帰もしません

This code fragment enumerates the subdirectories and files under a user’s Documents directory and processes all files with an extension of .doc: このコード断片は、ユーザのDocumentsディレクトリの下の下位ディレクトリとファイルを列挙します、そして.docの拡張子を持つすべてのファイルを処理します:


NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:  @"Documents"];
NSFileManager *localFileManager=[[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum =
    [localFileManager enumeratorAtPath:docsDir];
 
NSString *file;
while ((file = [dirEnum nextObject])) {
    if ([[file pathExtension] isEqualToString: @"doc"]) {
        // process the document
        [self scanDocument: [docsDir stringByAppendingPathComponent:file]];
    }
}

The NSDirectoryEnumerator class has methods for obtaining the attributes of the existing path and of the parent directory and for skipping descendants of the existing path. NSDirectoryEnumeratorクラスは、既存のパスのそして親ディレクトリの属性を取得するための、そして既存のパスの子孫を飛ばして省くためのメソッドを持ちます。

See Also 参照

Discovering Directory Contents ディレクトリ内容を発見する

Related Documentation 関連文書