Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globbing pattern to exclude files in directory, but include subdirectories

Tags:

glob

I have the following file hierarchy:

scripts
    someConfigFile.js
    anotherConfigFile.js

    someModuleDirectory
        someModule.js

    anotherModuleDirectory
        anotherModule.js

        subDirectory
            thirdModule.js

I want to match all the files in the module directories, but excude the config files contained in the scripts directory itself, using Glob:

var glob = require('glob');

console.log(glob.sync(unknownGlobPattern));

Required output (unordered):

[
    'someModuleDirectory/someModule.js',
    'anotherModuleDirectory/anotherModule.js',
    'anotherModuleDirectory/subDirectory/thirdModule.js'
]
like image 223
sennett Avatar asked Feb 01 '15 11:02

sennett


1 Answers

The following glob should work:

['./scripts/**/*', '!./scripts/*']

First part will include all files in all subdirectories. Second part will exclude files in starting directory.

like image 176
Jurijs Kovzels Avatar answered Sep 28 '22 07:09

Jurijs Kovzels