sennett
sennett

Reputation: 8424

Globbing pattern to exclude files in directory, but include subdirectories

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'
]

Upvotes: 9

Views: 41697

Answers (1)

Jurijs Kovzels
Jurijs Kovzels

Reputation: 6220

The following glob should work:

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

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

Upvotes: 11

Related Questions