Need to create new directory and text files

#1

Hello

We need to create text file from string content, When I a trying to create just directory then I am getting an error like “Directory ‘file:///…/myfolder’ could not be created”
I have also tried after giving read and wrote external storage permission but didn’t get any success.

Can you please guide us on this. As our aim is attaching that file in email, but for that first we need to create file and directory.

We are using Expo’s FileSystem.
Our Code as below

try {
      let folder = FileSystem.documentDirectory + "mailToStory"
      await FileSystem.makeDirectoryAsync(folder, {
        intermediates: true
      })

      var fi = await FileSystem.getInfoAsync(folder);

      alert(JSON.stringify(fi))
    } catch (error) {
      alert(error)
    }

Waiting for your answer.

#2

Hey @ips,

I just threw your code into a Snack and it is working as expected. I tested it on an iPhone 7 running iOS 11.4. Can you provide more information like what SDK version you are running, are you testing on a simulator or physical device, if physical device - what devices and what platform(s) are you getting the error on?

Cheers,

Adam

#3

Hello @adamjnav ,

Thanks for your reply.

We are using Samsung Android device. We are building application in that device through expo.
And its not creating any directory and throwing error, and expo version we are using is ^27.0.0.

closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.