I have a file mask in format like:
'/some/dir/*'
I want to match it with names:
'/some/dir/file1.txt'
'/some/dir/nested/file2.txt'
Is there a standard (common) solution in node.js to check whether name matches such mask?
I could convert mask to regExp, but I wonder if there more standard way of doing this?
The wildcard
module can help you:
var wildcard = require('wildcard');
var pattern = '/some/dir/*';
var files = [
'/some/dir/file1.txt',
'/some/dir/nested/file2.txt',
'/another/dir/file3.txt',
];
files.forEach(function(file) {
console.log(file, 'match?', wildcard(pattern, file));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.