Skip to content

uccu/files-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maintainability codecov GitHub issues GitHub

LICENSE

MIT

GOAL

Traverse all files in a folder

INSTALL

npm i files-import

HOW TO USE

#   Afolder
#     Afile
#     Bfile
#   Bfolder
#     Cfolder
#        Efile
#   Cfile
#   Dfile

const path = require('path');
const Factory = require('files-import');
const factory = new Factory('myFolder');
factory.map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# |Cfile
# |Dfile
# Afolder|Afile
# Afolder|Bfile
# Bfolder/Cfolder|Efile


factory
.exclude('Cfile')
.exclude('Dfile')
.include('A', Factory.PATH_TYPE.FOLDER)
.exclude('Afile', Factory.PATH_TYPE.FILE)
.map(file => {
    console.log( path.basename(file.path) );
});


# Bfile

INCLUDE

// fac.include = 'folder';
// fac.include = /folder/;
// fac.include('folder');
// fac.include(/folder/);
factory.include(function(f) {
    return f.path.indexOf('folder') !== -1;
}).map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# Afolder|Afile
# Afolder|Bfile
# Bfolder/Cfolder|Efile

EXCLUDE

// fac.exclude = 'folder';
// fac.exclude = /folder/;
// fac.exclude('folder');
// fac.exclude(/folder/);
factory.exclude(function(f) {
    return f.path.indexOf('folder') !== -1;
}).map(file => {
    console.log(
        file.folders.join('/') + '|' + path.basename(file.path)
    )
});

# |Cfile
# |Dfile

SUGGESTION

/** wrong */
factory.map(function() {
    if(file.folders[0] === 'test') return;
    // other code
});

/** ok */
factory.exclude(f => {
    return f.folders[0] === 'test';
}).map(function() {
    // other code
});

/** traverse files in folder exclude folder inside */
factory.exclude(f => {
    return f.folders[0];
}).map(function() {
    // other code
});

# |Cfile
# |Dfile