Javascript 节点glob中的方括号有问题

Javascript 节点glob中的方括号有问题,javascript,node.js,glob,Javascript,Node.js,Glob,我正在使用这个软件包 我面临的问题是,每当我的路径包含方括号[]时,它不会给我任何文件 我就是这样做的: const glob = require('glob') const path = 'E:/files/Example [Folder] 1' const files = glob.sync(path + '/**/*', { nobrace: true, noext: true }) 它对括号或大括号{}没有问题,但对方括号[]没有问题 我正在使用Windows。我怎样才能解

我正在使用这个软件包

我面临的问题是,每当我的路径包含方括号[]时,它不会给我任何文件

我就是这样做的:

const glob = require('glob')

const path = 'E:/files/Example [Folder] 1'
const files = glob.sync(path + '/**/*', { 
  nobrace: true,
  noext: true
})
它对括号或大括号{}没有问题,但对方括号[]没有问题

我正在使用Windows。我怎样才能解决这个问题?请帮忙

大括号[和]具有特殊含义,如*:

[…]匹配字符范围,类似于RegExp范围。如果范围的第一个字符为!或者^然后它匹配不在范围内的任何字符

所以你需要用电脑逃离他们\

但在您的情况下,您最喜欢查找root或cwd

cwd要搜索的当前工作目录。默认为process.cwd

根-以/开头的图案将安装到的位置。Unix系统上的默认值为path.resolveptions.cwd、//和Windows上的C:\或类似值


我不想成为显而易见的解决方案的承载者,但文件/文件夹名称是否需要包含[]字符?虽然它是完全有效的,但它似乎很不传统。它不应该是带有双斜杠的E://吗?事实上,我正在开发一个下载程序,让用户下载文件。某些文件夹包含[]。所以我需要一个解决方案。@ZhongWang它使用单斜杠。非常感谢!
const glob = require('glob')

const path = 'E:/files/Example \\[Folder\\] 1'
const files = glob.sync(path + '/**/*', { 
  nobrace: true,
  noext: true
})
const path = 'E:/files/Example [Folder] 1'
const files = glob.sync('**/*', { 
  nobrace: true,
  noext: true,
  cwd: path
})
const path = 'E:/files/Example [Folder] 1'
const files = glob.sync('/**/*', { 
  nobrace: true,
  noext: true,
  root: path
})