Navigate back to the homepage

How to delete file in react native

Infinitbility
React Native
June 20th, 2021 · 1 min read
How to delete file in react native

Hello Friends,

Welcome To Infinitbility!

This article will help you to delete your file in react native using react-native-fs library.

Here, we are use react-native-fs library to check file available or not and delete file.

Let’s start today’s topic How to delete file in react native

react-native-fs provide unlink component to delete file available or not it will throw error and it works on both platform (android, and iOS).

unlink(filepath: string): Promise<void>

react-native-fs unlink function required filepath to delete files and return with promise whitch means you have to use await for get proper result.

Installation

First we have need to install react-native-fs library on our project.

1npm install react-native-fs --save

Extra steps for iOS Installation

  • add below code to your podfile
1pod 'RNFS', :path => '../node_modules/react-native-fs'
  • install library
1pod install

Here, i am sharing how i delete file using react-native-fs unlink in react native, you have to just pass filepath to delete function with await.

One more thing, first you have to check file exists and then call unlink else you will get error.

let’s understand with code example.

  • add below code top of your file
1// require the module
2var RNFS = require('react-native-fs');
  • exists usebility
1async function delteFiles(filepath) {
2 let exists = await RNFS.exists(filepath);
3 if(exists){
4 // exists call delete
5 await RNFS.unlink(filepath);
6 console.log("File Deleted");
7 }else{
8 console.log("File Not Available")
9 }
10}

Subscribe Our Newsletter You will get monthly free programming book

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Subscribe Our Newsletter You will get monthly free programming book

Tutorials

React Native

Categories

More articles from Infinitbility

How to check file is exist or not in react native

How to check file is exist or not in react native

React Native file exists example

June 19th, 2021 · 1 min read
isMicrophone mute and unmute issue in RPScreenRecorder

isMicrophone mute and unmute issue in RPScreenRecorder

Replaykit isMicrophone mute and unmute issue when screen recording start

June 18th, 2021 · 1 min read
© 2020–2021 Infinitbility
Disclaimer
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]