How to use the react-native-fs.readDir 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 DefinitelyTyped / DefinitelyTyped / react-native-fs / react-native-fs-tests.ts View on Github external
import * as RNFS from 'react-native-fs';


// get a list of files and directories in the main bundle
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
  .then((result) => {
    console.log('GOT RESULT', result);

    // stat the first file
    return Promise.all([RNFS.stat(result[0].path), result[0].path]);
  })
  .then((statResult) => {
    if (statResult[0].isFile()) {
      // if we have a file, read it
      return RNFS.readFile(statResult[1], 'utf8');
    }

    return 'no file';
  })
  .then((contents) => {
    // log the file contents
github egm0121 / splitcloud-app / modules / FileDownloadManager.js View on Github external
cleanupIncompleteDownloads(){

    RNFS.readDir(this.options.cachePath).then((pathsArr) => {
      let deleteAllPaths = pathsArr.filter(
        file => this._isTempDownloadFile(file.name)
      )
      .map(f =>{ console.log('del file'+f.name); return f})
      .map(file => RNFS.unlink(file.path));

      return Promise.all(deleteAllPaths);
    });
  }
  deleteAllStorage(){
github soutot / react-native-voice-record-app / src / App.js View on Github external
updateDataSource() {
		RNFS.readDir(AudioUtils.DocumentDirectoryPath)
		.then((result) => {
			this.setState({recordedFiles: result});
			this.setState({
			  dataSource: this.state.dataSource.cloneWithRows(result),
			})
			return Promise.all([RNFS.stat(result[0].path), result[0].path]);
		})
		.catch((err) => {
			console.log(err.message, err.code);
		});
	}
github crownstone / CrownstoneApp / js / views / dev / firmwareTesting / DEV_DFU.tsx View on Github external
getZips() {
    let localPath = FileUtil.getPath()
    RNFS.readDir(localPath)
      .then((data) => {
        let zippies = [];
        data.forEach((d) => {
          let name = d.name;
          if (name.substr(name.length-4) === '.zip') {
            zippies.push(name);
          }
        })
        this.setState({availableFirmwares: zippies});
      })
  }
github crownstone / CrownstoneApp / js / util / FileUtil.ts View on Github external
index: function() {
    return RNFS.readDir(FileUtil.getPath())
  },
github laurent22 / joplin / ReactNativeClient / lib / fs-driver-rn.js View on Github external
async readDirStats(path, options = null) {
		if (!options) options = {};
		if (!('recursive' in options)) options.recursive = false;

		let items = await RNFS.readDir(path);
		let output = [];
		for (let i = 0; i < items.length; i++) {
			const item = items[i];
			const relativePath = item.path.substr(path.length + 1);
			output.push(this.rnfsStatToStd_(item, relativePath));

			output = await this.readDirStatsHandleRecursion_(path, item, output, options);
		}
		return output;
	}
github codeestX / MoeFM / js / page / LocalListPage.js View on Github external
async parseMP3Res(path) {
        let existDir = await RNFS.exists(path).then(boolean => boolean);
        if (!existDir) return;
        let results = await RNFS.readDir(path);
        let mp3Res = results.map((item) => {
            if (item.isDirectory()) {
                this.parseMP3Res(item.path);
            }
            return item;
        }).filter((item) => item.name.includes('.mp3'));
        this.setState({data: this.state.data.concat(mp3Res)});
    }
}
github totorototo / strava / app / store / services / helpers / file.js View on Github external
export const readDir = (
  path = `${RNFS.ExternalStorageDirectoryPath}/Download`
) => RNFS.readDir(path);
github mybigday / react-native-media-player / example / app.js View on Github external
loadResource = () => {
		RNFS.readDir(RNFS.DocumentDirectoryPath).then((files) => {
			let imageFileList = files.filter((file) => (file.path.indexOf("jpg") >= 0)).map((file) => {
				return {
					path: file.path,
					name: file.name
				};
			});
			let videoFileList = files.filter((file) => (file.path.indexOf("mp4") >= 0)).map((file) => {
				return {
					path: file.path,
					name: file.name
				};
			});
			let audioFileList = files.filter((file) => (file.path.indexOf("mp3") >= 0)).map((file) => {
				return {
					path: file.path,
					name: file.name
github textileio / photos / App / SDK / migration.ts View on Github external
moveTextileFiles = async (repoPath: string): Promise => {
    const files = await RNFS.readDir(RNFS.DocumentDirectoryPath)
    for (const file of files) {
      if (file.path !== repoPath && file.name !== 'RCTAsyncLocalStorage_V1') {
        await RNFS.moveFile(file.path, `${repoPath}/${file.name}`)
      }
    }
  }
}