Running a node app to read a directory
fs.readdirSync('/Users/edwardthompson/Dropbox/Apps/EvidentiaSoftware/records/thompson-hayward');
I consistently get
Stack:
error properties: Object({ errno: -2, syscall: 'scandir', code: 'ENOENT', path: '/Users/edwardthompson/Dropbox/Apps/EvidentiaSoftware/records/thompson-hayward' })
Error: ENOENT: no such file or directory, scandir '/Users/edwardthompson/Dropbox/Apps/EvidentiaSoftware/records/thompson-hayward'
But I know the directory is there
ls -al /Users/edwardthompson/Dropbox/Apps/EvidentiaSoftware/records/thompson-hayward
total 0
drwxr-xr-x@ 9 edwardthompson staff 288 Jan 18 2019 .
drwxr-xr-x@ 6 edwardthompson staff 192 Aug 29 12:30 ..
drwxr-xr-x@ 9 edwardthompson staff 288 Jan 18 2019 Births
drwxr-xr-x@ 4 edwardthompson staff 128 Jan 18 2019 Census
drwxr-xr-x@ 3 edwardthompson staff 96 Jan 18 2019 Deaths
drwxr-xr-x@ 7 edwardthompson staff 224 Jan 18 2019 Marriages
drwxr-xr-x@ 4 edwardthompson staff 128 Jan 18 2019 Military
drwxr-xr-x@ 3 edwardthompson staff 96 Jan 18 2019 Other
drwxr-xr-x@ 8 edwardthompson staff 256 Jan 18 2019 books
Not sure how to proceed
fs.lstat gives me the same ENOENT results. The Dropbox directory has extended attributes (can't find getfattr)
I tried /user/... and it did not make a difference
readdir(). It is the same as fs. readdirSync(), but has the callback function as the second parameter.
The fs. readdir() method is used to asynchronously read the contents of a given directory. The callback of this method returns an array of all the file names in the directory. The options argument can be used to change the format in which the files are returned from the method.
isDirectory() method is an inbuilt application programming interface of class fs. Dirent within File System module which is used to check if the particular dirent describes a Directory or not. Syntax: const dirent.isDirectory()
const path = require('path');
const dirName = path.join(__dirname, '/ (../)x? /records/thompson-hayward');
(../)x? replace this with ../ how many times you need
fs.readdirSync(dirName).forEach(folder => {
// code here
});
You could try using path.resolve()
:
fs.readdirSync(path.resolve(‘Users’, ‘edwardthompson’, ‘Dropbox’, ‘Apps’, ‘EvidentiaSoftware’, ‘records’, ‘thompson-hayward’));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With