manidlou / node-klaw-sync

Node.js recursive synchronous fast file system walker
MIT License
157 stars 10 forks source link

depthLimit option is ignored when filter option is set #14

Closed Lukas238 closed 5 years ago

Lukas238 commented 5 years ago

Hi,

When using this options, I can only access the level 0 (default) of the directory been read.

I want to match any "/folder/subfolder" that match my regexp (link: https://regex101.com/r/EYiftm/1).

The regexp seem to be correct, but when I walk the root folder with the option "deepthLimit:1" (so to get the folder and subfolder names in the path) and the filter option, I only get the folder in deep 0.

If I disable the filteroption, I get the folder/subfolder as expected.

depthLimit: 1 get ignored when using with filter option.

function filter_yearFolder(item){
    return /\/\d{4}\/.+$/.test(item.path);
}

let dirs = klawSync("/Users/user1/work", {nofile: true, depthLimit: 1, filter: filter_yearFolder})
 console.log(dirs);

Removing filter option let depthLimit:1work as expected (but sans any filtering)

let dirs = klawSync("/Users/user1/work", {nofile: true, depthLimit: 1})
 console.log(dirs);

Best regards!!

manidlou commented 5 years ago

@Lukas238 if I understand correctly, you have a directory structure like /2016/01.January (/year/month) under /Users/user1/work as root directory.

By examining your example and looking at your regex link results, seems like klawSync behaves correctly because paths like /Users/user1/work/2016 don't match your regex! Although paths like /Users/user1/work/2016/01.January do match your regex but these are subfolders and they never get traversed because their parent folders don't match the regex!

manidlou commented 5 years ago

closing for lack of response!