react-native-fs 三方组件的常规使用

react-native-fs RN文件管理三方组件

const RNFS = require("react-native-fs");
//创建文件夹路径
var imgPath = RNFS.DocumentDirectoryPath + '/imgDir';
RNFS.mkdir(imgPath);
// 创建文件夹 DocumentDirectoryPath imgPath
//判断文件夹是否存在,不存在的重新创建
                RNFS.exists(imgPath).then((res) => {
                    console.log('res---112313-', res);
                    if (res) {
                        //文件存在
                        console.log('文件存在----', imgPath);

                    } else {
                        RNFS.mkdir(imgPath);
                        console.log('文件不存在----', imgPath);
                    }
                });
 // 复制文件到指定文件夹
                console.log('imgPath----', imgPath);
                let infoList: any = []
                if (photos.path.indexOf('\\') > -1) {
                    //包含
                    infoList = photos.path.split('\\')
                } else {
                    //不包含
                    infoList = photos.path.split('/')
                }

                let tempPath = `${imgPath}/${infoList[infoList.length - 1]}`;
                RNFS.copyFile(photos.path, tempPath).then((res) => {

                    console.log('res----', res);

                });

// 删除文件
    const _deleteFilePath = (tempPath) => {
        RNFS.unlink(tempPath)
            .then(() => console.log('已经被删除'))
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容