Open dzek69 opened 7 years ago
You could add a filter function, and "stat" each path using a try...catch. If it fails, returning false will allow you to skip that troublesome entry.
Hi,
I'm running into the same issue and I'm not sure how change the example code to keep it running while ignoring the error. Please advice :-)
Depending on what you are doing, this might work. I just wrapped my klaw call with fs-extra's pathExists, and if you want to scan a list of folders just create an outer klaw call that checks only for directories and passes the current folder to the below.
fs.pathExists(folder, (err, exists) => {
if (exists) {
klaw(folder, { depthLimit: depth })
.pipe(excludeDirFilter)
.on('data', item => {
files.push(item.path);
})
.on('error', (err, item) => {
console.log('klaw error: ', item);
throw new Error(`klawError: ${err}`);
})
.on('end', () => {cb(files);});
} else {
cb({ error: `file/folder does not exist: ${folder}`});
}
});
One solution is to use vanilla Node:
// Vanilla Node walker, hard to check done when using default async implementation.
let walk = dir => {
fs.readdirSync(dir).forEach(item => {
let itemPath = path.join(dir, item)
try {
var stats = fs.statSync(itemPath)
} catch (e) {
console.log(e)
return
}
if (stats.isDirectory()) walk(itemPath)
else if (stats.isFile()) patch(itemPath)
})
}
walk(project_folder)
console.log("Done.")
Did anyone find a solution to this issue? I would prefer to use Klaw over the vanilla Node (as suggested above). Any help is much appreciated !
Hello,
I really appreciate this awesome package, but I cannot configure it to continue on error.
If directory access error occurs (not sure about file errors) then
klaw
just emitserror
and stops.end
isn't called.I'd like to continue seeking through directories.
Currently I cannot use
klaw
to scan whole readable filesystem, because it surely won't have access to some directories.Any solutions?