maroodb
maroodb

Reputation: 1108

node glob sync returns empty array


I am using glob nodejs module to sync files using patterns

I did :

 glob.sync('C:\Users\maroodb\project\config\*.json')

but it returns : [] such the config folders contains 15 files *.json

is there a problem with windows path ?

Upvotes: 4

Views: 5693

Answers (1)

Sophie
Sophie

Reputation: 171

Yes, a windows path will not work. A glob pattern is always in POSIX format. You just have to change the separator:

glob.sync('C:/Users/maroodb/project/config/*.json');

If the path is dynamic, you have to replace the separator:

glob.sync('C:\Users\maroodb\project\config\*.json'.replace(/\\/g, '/'))

Upvotes: 17

Related Questions