<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateMLComponents",
  "identifier" : "/documentation/CreateMLComponents/AnnotatedFiles/init(labeledByNamesAt:separator:index:type:continueOnFailure:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Create ML Components",
      "CreateMLComponents"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents14AnnotatedFilesV16labeledByNamesAt9separator5index4type17continueOnFailureAC10Foundation3URLV_SJSi22UniformTypeIdentifiers6UTTypeVSbtKcfc"
  },
  "title" : "init(labeledByNamesAt:separator:index:type:continueOnFailure:)"
}
-->

# init(labeledByNamesAt:separator:index:type:continueOnFailure:)

Reads training examples from a directory containing files having their labels in the name.
The name can contain multiple words separated by a `separator`. So the `index` tells the
position of the label in the file name.
Files with incorrect name format are ignored.

```
init(labeledByNamesAt url: URL, separator: Character = ".", index: Int = 0, type: UTType, continueOnFailure: Bool = false) throws
```

## Parameters

`url`

URL of directory containing the files.

`separator`

The separator used in the name. Default value is “.”

`index`

Index of the label in the file name. Default value is 0.

`type`

Type of files.

`continueOnFailure`

A Boolean value indicating whether to continue reading files after
encountering a file that is not readable. The default value is `false`.

## Discussion

Take for example this directory structure:

```
/
    fold1-foo-file1.png
    fold1-foo-file2.png
    fold2-foo-file3.png
    fold1-bar-file4.png
    fold1-bar-file5.png
    fold2-bar-file6.png
```

When we specify separator as “-” and index as 1, it would produce two labels (foo and bar) with three
URLs each.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)