itinance / itinance/react-native-fs

Use `readFile` to catch an error: EISDIR: illegal operation on a directory

Open
#995 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

> description

I want to make a version tag, so after writing the content, I want to read the content of this file.
But for unknown reasons, it caught this error.
`EISDIR: illegal operation on a directory, read '/data/user/0/com.baorun.handbook.a08/files/360/file_version.txt' EISDIR`

> sort code

```javascript
const init = async () => {

RNFS.readDir(`${RNFS.DocumentDirectoryPath}/360`)
.then((result: { path: any }[]) => {

return Promise.all([RNFS.stat(result[5].path), result[5].path]);

})
.then((statResult: any[]) => {
consoel.log('print StatResult:',statResult)
if (statResult[0].path) {
console.log('Have this file')
// if we have a file, read it
return RNFS.readFile(statResult[1], 'utf8');
}

return 'no file';

})
.then((content: any) => {

console.log(content)

})
.catch((err: { message: any; code: any }) => {

console.log(err.message, err.code);

});

}

init().then(null)

```

> print statResult

```javascript
[
{
"ctime": 2021-04-08T08:15:10.000Z, "isDirectory": [Function isDirectory], "isFile": [Function isFile],
"mode": undefined,
"mtime": 2021-04-08T08:15:10.000Z, "originalFilepath": "/data/user/0/com.baorun.handbook.a08/files/360/file_version.txt",
"path": "/data/user/0/com.baorun.handbook.a08/files/360/file_version.txt",
"size": 4096
},

"/data/user/0/com.baorun.handbook.a08/files/360/file_version.txt"
]

```

> version info

"react-native-fs": "^2.16.6",

![image](https://user-images.githubusercontent.com/16655229/114114335-41111900-9913-11eb-8397-7d606e424dea.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.