美文网首页
react-native-fs 三方组件的常规使用

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

作者: WindFlyCloud | 来源:发表于2023-04-12 10:55 被阅读0次

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('已经被删除'))
    }

相关文章

网友评论

      本文标题:react-native-fs 三方组件的常规使用

      本文链接:https://www.haomeiwen.com/subject/ksanddtx.html