2016-01-02 29 views
1

鑑於目錄結構:什麼是glob模式匹配不以下劃線開頭的所有文件忽略那些以下劃線開頭的目錄?

a/ 
    b/ 
    _private/ 
     notes.txt 
    c/ 
     _3.txt 
     1.txt 
     2.txt 
    d/ 
     4.txt 
    5.txt 

如何可以寫一個glob模式,其選擇如下路徑(與NPM模塊glob兼容)?

a/b/c/1.txt 
a/b/c/2.txt 
a/b/d/4.txt 
a/b/5.txt 

這是我曾嘗試:

// Find matching file paths inside "a/b/"... 
glob("a/b/[!_]**/[!_]*", (err, paths) => { 
    console.log(paths); 
}); 

但這只是發出:

​​

回答

1

隨着一些試驗和錯誤(和grunt (minimatch/glob) folder exclusion的幫助)我發現下面似乎達到我正在尋找的結果:

// Find matching file paths inside "a/b/"... 
glob("a/b/**/*", { 
    ignore: [ 
     "**/_*",  // Exclude files starting with '_'. 
     "**/_*/**" // Exclude entire directories starting with '_'. 
    ] 
}, (err, paths) => { 
    console.log(paths); 
}); 
相關問題