passback filename along with path
jasan-s opened this issue · 3 comments
jasan-s commented
My current solution is :
const temp = file.toString().split("\\")
const filename = temp.pop()
not sure if its robust
nspragg commented
Hi @jasan-s. Can you provide the filehound call you are making?
If you're are trying to extract the filenames (without path) from the results, I'd map over the results and extract the filename using path.basename
jasan-s commented
const files = FileHound.create()
.paths(__dirname + '/../images/master/')
.ext('jpg') // only jpg extentions
.find()
files.then((files) => {
files.forEach((file) => {
const temp = file.toString().split("\\")
const filename = temp.pop()
})
})
Can you elaborate on how to use path.basename
nspragg commented
Here is an example:
const FileHound = require('filehound');
const path = require('path');
function getNames(files) {
return files.map((file) => {
return path.basename(file, 'jpg');
});
}
FileHound.create()
.paths(__dirname + '/../images/master/')
.ext('jpg')
.find()
.then(getNames)
.then(console.log);