<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Bundle/path(forResource:ofType:inDirectory:)-swift.method",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(im)pathForResource:ofType:inDirectory:"
  },
  "title" : "path(forResource:ofType:inDirectory:)"
}
-->

# path(forResource:ofType:inDirectory:)

Returns the full pathname for the resource identified by the specified name and file extension and located in the specified bundle subdirectory.

```
func path(forResource name: String?, ofType ext: String?, inDirectory subpath: String?) -> String?
```

## Parameters

`name`

The name of the resource file.

    If you specify     `nil`    , the method returns the first resource file it finds that matches the remaining criteria.

`ext`

The filename extension of the files to locate.

    If you specify an empty string or     `nil`    , all the files in     `subpath`     and its subdirectories are returned. If an extension is provided the subdirectories are not searched.

`subpath`

The name of the bundle subdirectory.

## Return Value

The full pathname for the resource file, or `nil` if the file could not be located.

## Discussion

If `subpath` is `nil`, this method searches the top-level nonlocalized resource directory and the top-level of any language-specific directories. (In macOS, the top-level nonlocalized resource directory is typically called `Resources` but in iOS, it is the main bundle directory.) For example, suppose you have a Mac app with a modern bundle and you specify `@"Documentation"` for the `subpath` parameter. This method would first look in the `Contents/Resources/Documentation` directory of the bundle, followed by the `Documentation` subdirectories of each language-specific `.lproj` directory.

Whether this method recurses through subdirectories is dependent on the `extension` parameter. If `nil` or an empty string it will recurse, otherwise, it does not. (The search order for the language-specific directories corresponds to the user’s preferences.) For details on how localized resources are found, read [The Bundle Search Pattern](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW7) in [Bundle Programming Guide](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html#//apple_ref/doc/uid/10000123i).

## See Also

[`localizedString(forKey:value:table:)`](/documentation/Foundation/Bundle/localizedString(forKey:value:table:))

Returns a localized version of the string designated by the specified key and residing in the specified table.



---

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)