You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求react-native-fs中对应expo-file-system.getInfoAsync的替代方法

react-native-fs 对应 Expo FileSystem.getInfoAsync 的功能说明

有,react-native-fs 中的 stat() 方法就是与 Expo FileSystem.getInfoAsync 对应的功能,它可以获取文件或目录的详细元信息,包括是否存在、是否为文件/目录、大小、修改时间等。

使用示例

import RNFS from 'react-native-fs';

const fetchFileInfo = async (filePath) => {
  try {
    const fileStats = await RNFS.stat(filePath);
    console.log('文件/目录信息:', fileStats);
    // 返回的核心字段:
    // - exists: 布尔值,标识目标是否存在
    // - isFile: 布尔值,标识是否为文件
    // - isDirectory: 布尔值,标识是否为目录
    // - size: 数字,文件大小(字节)
    // - mtime: 数字,最后修改时间戳
    // - ctime: 数字,创建时间戳
  } catch (err) {
    console.error('获取信息失败:', err);
  }
};

如果仅需判断文件/目录是否存在,也可以使用 RNFS.exists(filePath) 方法,但 stat() 能提供更完整的信息,和 getInfoAsync 的能力覆盖范围更一致。

内容的提问来源于stack exchange,提问作者RT3516

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 01:25:29