Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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(){
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);
});
}
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});
})
}
index: function() {
return RNFS.readDir(FileUtil.getPath())
},
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;
}
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)});
}
}
export const readDir = (
path = `${RNFS.ExternalStorageDirectoryPath}/Download`
) => RNFS.readDir(path);
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
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}`)
}
}
}
}