How to check file exist in React Native

Romik Makavana
2 min readFeb 20, 2023

--

Check Full Story…

To check if a file exists in React Native, you can use the RNFS (React Native File System) library. Here is an example:

First, you need to install react-native-fs by running this command in your project directory:

npm install react-native-fs

Then, you can use the RNFS.exists() method to check if a file exists. Here is an example code:

In this example, RNFS.DocumentDirectoryPath specifies the path to the app's document directory, and example.txt is the name of the file you want to check. The RNFS.exists() method returns a promise that resolves to true if the file exists and false if it does not exist. If there is an error, the promise is rejected and an error message is logged to the console.

Note that RNFS library can only access files within the app's sandbox, such as the document directory and cache directory, so you cannot use it to check if a file exists in external storage or other apps' directories.

Here I’ve used ‘react-native-fs’ package to check file exist, you can also check file exist without this package.

Using FileSystem API

Hold the clap button to clap as much as you can! Clapping is free and it helps me get the content out to more people ❤️

--

--