Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mkdir with React-Native-FS

I'm trying to add functionality to my RN app that will allow users to create a new directory within their phone's file system.

I have tried to write the code so that the function creates a directory in the path /storage/emulated/0/AppName/NewFolder, since /storage/emulated/0 is the same path that is used by other apps I use to store user data (such as recording apps)

    makeDirectory = () => {
        const { currentFolder, units } = this.props;

        const directoryName = 'New Folder'
        const currentDirectory = units

        const absolutePath = `/storage/emulated/0/MyApp/${currentDirectory}`

        RNFS.mkdir(absolutePath)
            .then((result) => {
                console.log('result', result)
            })
            .catch((err) => {
                console.warn('err', err)
            })
    }

However, this is just giving me an error: directory could not be created. I feel I am missing something here, and am not supposed to be saving the files like this to the phone's system.

My ultimate goal is to have the app with it's own folder system that will be mirrored within /storage/emulated/0/MyApp/home

like image 549
Tycholiz Avatar asked Jan 26 '23 13:01

Tycholiz


1 Answers

 const    AppFolder    =     'DirNameyouwant';
 const DirectoryPath= RNFS.ExternalStorageDirectoryPath +'/'+ AppFolder;
 RNFS.mkdir(DirectoryPath);
like image 103
sandeep rathod Avatar answered Jan 29 '23 15:01

sandeep rathod