node-glob not finding file that exists and is matched by minimatch (Windows 10)

787 views Asked by At

I am trying to write a glob pattern that will search for intellij binaries (roughly), but not search inside C:\Windows since there will not likely be any in there. I've added a bunch of minimatch examples that seem to work as intended, but the glob.sync is not finding the file. Any help is greatly appreciated!

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)
}

output of this script:

true
true
false
true
true


glob results:
[]


file found

I expect that executable to be listed in the array of globResults, of course.

1

There are 1 answers

0
Daniel Goudie On

This ended up being what I wanted:

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)