---
title: "CFBundleCreateBundlesFromDirectory(_:_:_:)"
framework: corefoundation
role: symbol
role_heading: Function
path: "corefoundation/cfbundlecreatebundlesfromdirectory(_:_:_:)"
---

# CFBundleCreateBundlesFromDirectory(_:_:_:)

Searches a directory and constructs an array of CFBundle objects from all valid bundles in the specified directory.

## Declaration

```swift
func CFBundleCreateBundlesFromDirectory(_ allocator: CFAllocator!, _ directoryURL: CFURL!, _ bundleType: CFString!) -> CFArray!
```

## Parameters

- `allocator`: The allocator to use to allocate memory for the new object. Pass NULL or doc://com.apple.corefoundation/documentation/CoreFoundation/kCFAllocatorDefault to use the current default allocator.
- `directoryURL`: The location of the directory to search for valid bundles.
- `bundleType`: The abstract type of the bundles to locate and create. The type is expressed as a filename extension, such as bundle. Pass NULL to create CFBundle objects for bundles of any type.

## Return Value

Return Value A CFArray object containing CFBundle objects created from the contents of the specified directory. Returns an empty array if no bundles exist at directoryURL, and NULL if there was a memory allocation problem. Ownership follows the The Create Rule.

## Discussion

Discussion The array returned by this function will not contain stale CFBundle references. Special Considerations The The Create Rule applies both to the array returned and to the bundles in the array. In order to properly dispose of the returned value, you must release the array and any bundles returned in the array.

## See Also

### Creating and Accessing Bundles

- [CFBundleCreate(_:_:)](corefoundation/cfbundlecreate(_:_:).md)
- [CFBundleGetAllBundles()](corefoundation/cfbundlegetallbundles().md)
- [CFBundleGetBundleWithIdentifier(_:)](corefoundation/cfbundlegetbundlewithidentifier(_:).md)
- [CFBundleGetMainBundle()](corefoundation/cfbundlegetmainbundle().md)
