Skip to content

MissingCore/react-native-actual-path

Repository files navigation

@missingcore/react-native-actual-path

NPM Version License

A port of react-native-actual-path that supports both the new & old architectures.

Also supports returning paths from the device's SDCard slot (tested using an emulator).

Installation

npm install @missingcore/react-native-actual-path

Usage

Important

This might not work directly with the content:// URI returned from expo-file-system's StorageAccessFramework.requestDirectoryPermissionsAsync(). Below is an example on how to get around this.

import { getActualPath } from '@missingcore/react-native-actual-path';
import { StorageAccessFramework as SAF } from 'expo-file-system';

export async function getDirLocation() {
  const permissions = await SAF.requestDirectoryPermissionsAsync();
  if (!permissions.granted) return null;
  try {
    const dirContents = await SAF.readDirectoryAsync(permissions.directoryUri);
    const dirItem = dirContents[0];
    if (!dirItem) throw new Error('No items found in directory.');
    const resolved = await getActualPath(dirItem);
    return resolved ? resolved.split('/').slice(0, -1).join('/') : null;
  } catch (err) {
    console.log(err);
    return null;
  }
}

References

License

MIT

About

A port of `react-native-actual-path` that supports both the new & old architectures.

Resources

License

Stars

Watchers

Forks

Packages

No packages published