我正在尝试编写一个glob模式,它将(大致)搜索intellij二进制文件,但不在C:\ Windows内部搜索,因为其中可能没有任何二进制文件。我添加了许多minimatch示例,这些示例似乎可以按预期工作,但是glob.sync找不到文件。任何帮助将不胜感激!
var minimatch = require("minimatch")
var globSync = require('glob').sync
const FILE_THAT_EXISTS = 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.1/bin/idea64.exe';
const globPattern = `C:/!(Windows)/JetBrains/IntelliJ*/bin/idea64.exe`;
console.log(minimatch("C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.1/bin/idea64.exe", globPattern))
console.log(minimatch("C:/Program Files (x86)/JetBrains/IntelliJ IDEA 2019.1.1/bin/idea64.exe", globPattern))
console.log(minimatch("C:/Windows/JetBrains/IntelliJ IDEA 2019.1.1/bin/idea64.exe", globPattern))
console.log(minimatch("C:/Software/JetBrains/IntelliJ IDEA 2019.1.1/bin/idea64.exe", globPattern))
console.log(minimatch(FILE_THAT_EXISTS, globPattern));
console.log('\n')
const globResults = globSync(globPattern, {})
console.log(`glob results:`)
console.log(globResults);
console.log('\n')
// Verify that file actually exists:
var fs = require('fs');
try {
fs.accessSync(FILE_THAT_EXISTS)
console.log('file found');
} catch (e) {
console.log('file NOT found')
console.error(e)
}
此脚本的输出:
true
true
false
true
true
glob results:
[]
file found
我希望该可执行文件当然会在globResults数组中列出。
答案 0 :(得分:0)
这最终就是我想要的:
var globSync = require('glob').sync
const globPattern = `/!(windows)/jetbrains/intellij*/bin/idea64.exe`;
const globResults = globSync(globPattern, { nocase: true, strict: false, silent: true })
console.log(`glob results:`, globResults)