---
title: "path(forResource:ofType:inDirectory:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/bundle/path(forresource:oftype:indirectory:)-swift.type.method"
---

# path(forResource:ofType:inDirectory:)

Returns the full pathname for the resource file identified by the specified name and extension and residing in a given bundle directory.

## Declaration

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

## Parameters

- `name`: The name of a resource file contained in the directory specified by bundlePath. If you specify nil, the method returns the first resource file it finds with the specified extension.
- `ext`: The filename extension of the file to locate. If you specify an empty string or nil, the extension is assumed not to exist and the file is the first file encountered that exactly matches name.
- `bundlePath`: The path of a top-level bundle directory. This must be a valid path. For example, to specify the bundle directory for a Mac app, you might specify the path /Applications/MyApp.app.

## Return Value

Return Value The full pathname for the resource file or nil if the file could not be located. This method also returns nil if the bundle specified by the bundlePath parameter does not exist or is not a readable directory.

## Discussion

Discussion For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide. note: This method is best suited only for the occasional retrieval of resource files. In most cases where you need to retrieve bundle resources, it is preferable to use the NSBundle instance methods instead.

## See Also

### Related Documentation

- [localizedString(forKey:value:table:)](foundation/bundle/localizedstring(forkey:value:table:).md)

### Finding resource files

- [url(forResource:withExtension:subdirectory:)](foundation/bundle/url(forresource:withextension:subdirectory:).md)
- [url(forResource:withExtension:)](foundation/bundle/url(forresource:withextension:).md)
- [urls(forResourcesWithExtension:subdirectory:)](foundation/bundle/urls(forresourceswithextension:subdirectory:).md)
- [url(forResource:withExtension:subdirectory:localization:)](foundation/bundle/url(forresource:withextension:subdirectory:localization:).md)
- [urls(forResourcesWithExtension:subdirectory:localization:)](foundation/bundle/urls(forresourceswithextension:subdirectory:localization:).md)
- [url(forResource:withExtension:subdirectory:in:)](foundation/bundle/url(forresource:withextension:subdirectory:in:).md)
- [urls(forResourcesWithExtension:subdirectory:in:)](foundation/bundle/urls(forresourceswithextension:subdirectory:in:).md)
- [path(forResource:ofType:)](foundation/bundle/path(forresource:oftype:).md)
- [path(forResource:ofType:inDirectory:)](foundation/bundle/path(forresource:oftype:indirectory:)-swift.method.md)
- [path(forResource:ofType:inDirectory:forLocalization:)](foundation/bundle/path(forresource:oftype:indirectory:forlocalization:).md)
- [paths(forResourcesOfType:inDirectory:)](foundation/bundle/paths(forresourcesoftype:indirectory:)-swift.method.md)
- [paths(forResourcesOfType:inDirectory:forLocalization:)](foundation/bundle/paths(forresourcesoftype:indirectory:forlocalization:).md)
- [paths(forResourcesOfType:inDirectory:)](foundation/bundle/paths(forresourcesoftype:indirectory:)-swift.type.method.md)
