How to use the react-native-fs.exists function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github josephroquedev / campus-guide / src / util / Configuration.ts View on Github external
async function _getTextFile(textFile: string): Promise {
  // First, make sure the file exists
  const dir = CONFIG_SUBDIRECTORIES.text;
  const exists = await RNFS.exists(CONFIG_DIRECTORY + dir + textFile);

  if (!exists) {
    throw new Error(`Text file '${dir}${textFile}' does not exist.`);
  }

  // Load and parse the text file
  const raw = await RNFS.readFile(CONFIG_DIRECTORY + dir + textFile, 'utf8');

  return raw;
}
github banli17 / react-native-update-app / index.js View on Github external
androidUpdate = async () => {
        let _this = this
        const {url, filename, version} = this.fetchRes
        // 按照目录/包名/文件名 存放,生成md5文件标识

        this.filePath = `${RNFS.ExternalDirectoryPath}/${filename}${version}.apk`

        // 检查包是否已经下载过,如果有,则直接安装
        let exist = await RNFS.exists(this.filePath)
        if (exist) {
            RNUpdateApp.install(this.filePath)
            this.hideModal()
            return
        }

        // 下载apk并安装
        RNFS.downloadFile({
            fromUrl: url,
            toFile: this.filePath,
            progressDivider: 2,   // 节流
            begin(res) {
                _this.jobId = res.jobId   // 设置jobId,用于暂停和恢复下载任务
                this.loading = true
            },
            progress(res) {
github crownstone / CrownstoneApp / js / cloud / sections / sync / syncEvents.ts View on Github external
let success = () => { actions.push({type: 'FINISHED_SPECIAL_USER', id: userEventId })};
    switch (payload.specialType) {
      case 'removeProfilePicture':
        promises.push(CLOUD.removeProfileImage({background: true}).then(() => { success(); })
          .catch((err) => {
            // even if there is no profile pic, 204 will be returned. Any other errors are.. errors?
            LOGe.cloud("syncEvents Special: Could not remove image from cloud", err);
          }));
        break;
      case 'uploadProfilePicture':
        if (!state.user.picture) {
          success();
        }
        else {
          promises.push(
            RNFS.exists(state.user.picture)
              .then((fileExists) => {
                if (fileExists === false) {
                  success();
                }
                else {
                  return CLOUD.uploadProfileImage(state.user.picture)
                }
              })
              .then(() => { success() })
              .catch((err) => {
                LOGe.cloud("syncEvents Special: Could not upload image to cloud", err);
              })
          )
        }
        break;
github agershun / alasql / src / utils / files.js View on Github external
utils.global.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
				fileSystem.root.getFile(
					path,
					{create: false},
					function(fileEntry) {
						cb(true);
					},
					function() {
						cb(false);
					}
				);
			});
		} else if (utils.isReactNative) {
			// If ReactNative
			var RNFS = require('react-native-fs');
			RNFS.exists(path)
				.then(function(yes) {
					if (cb) cb(yes);
				})
				.catch(function(err) {
					throw err;
				});
			//*/
		} else {
			// TODO Cordova, etc.
			throw new Error('You can use exists() only in Node.js or Apach Cordova');
		}
	};
github jayesbe / react-native-cacheable-image / image.js View on Github external
_deleteFilePath = (filePath) => {
        RNFS
        .exists(filePath)
        .then((res) => {
            if (res) {
                RNFS
                .unlink(filePath)
                .catch((err) => {});
            }
        });
    }
github celo-org / celo-monorepo / packages / mobile / src / geth / geth.ts View on Github external
async function deleteFileIfExists(path: string) {
  try {
    const gethLockFileExists = await RNFS.exists(path)
    if (gethLockFileExists) {
      Logger.debug('Geth@deleteFileIfExists', `Dir ${path} exists. Attempting to delete`)
      await RNFS.unlink(path)
      return true
    } else {
      Logger.debug('Geth@deleteFileIfExists', `Dir ${path} does not exist`)
      return true
    }
  } catch (error) {
    Logger.error('Geth@deleteFileIfExists', `Failed to delete ${path}`, error)
    return false
  }
}
github textileio / photos / App / Sagas / Migration.ts View on Github external
async function deleteFile(path: string) {
  if (await FS.exists(path)) {
    await FS.unlink(path)
  }
}
github EdgeApp / edge-react-gui / src / util / logger.js View on Github external
export async function readLogs () {
  try {
    let log = ''
    let exists

    exists = await RNFS.exists(path3)
    if (exists) {
      log = log + (await RNFS.readFile(path3))
    }
    exists = await RNFS.exists(path2)
    if (exists) {
      log = log + (await RNFS.readFile(path2))
    }
    exists = await RNFS.exists(path1)
    if (exists) {
      log = log + (await RNFS.readFile(path1))
    }
    return log
  } catch (err) {
    global.clog((err && err.message) || err)
  }
}
github celo-org / celo-monorepo / packages / mobile / src / geth / geth.ts View on Github external
async function genesisBlockAlreadyWritten(nodeDir: string): Promise {
  const genesisBlockFile = getGenesisBlockFile(nodeDir)
  if (!(await RNFS.exists(genesisBlockFile))) {
    return false
  }
  const fileStat: RNFS.StatResult = await RNFS.stat(genesisBlockFile)
  return fileStat.isFile() && new BigNumber(fileStat.size, 10).isGreaterThan(0)
}