Directory picker
This module allows you to pick a directory from the file system. The chosen directory can then be used for file I/O operations.
When requestLongTermAccess is set to true, your app will be able to access the directory even after the app is restarted.
If you've requested long-term access to a directory or file, the response object will contain BookmarkingResponse.
Please note there are some security limitations.
import { pickDirectory } from '@react-native-documents/picker'
return (
<Button
title="open directory"
onPress={async () => {
try {
const { uri } = await pickDirectory({
requestLongTermAccess: false,
})
// do something with the uri
} catch (err) {
// see error handling section
console.error(err)
}
}}
/>
)
How it works
- Android
- iOS
Open mode uses Intent.ACTION_OPEN_DOCUMENT_TREE internally.
Open mode uses UIDocumentPickerViewController init(forOpeningContentTypes:asCopy:) internally.
Writing to the directory location
In order to write to the user-selected location, this approach needs to be used:
- on Android: https://stackoverflow.com/a/61120265
- on iOS: docs
Releasing Long Term Access
This is an Android-only feature. When you no longer need access to the file or location, you should release the long-term access by calling releaseLongTermAccess. Calling this on iOS will resolve.
See Android documentation for more information.
Releasing (stopping) Secure Access
This is an iOS-only feature. When you no longer need access to the file or location, you should release the secure access by calling releaseSecureAccess. Calling this on Android will resolve.
See iOS documentation for more information.