本文整理汇总了TypeScript中node-dir.subdirs函数的典型用法代码示例。如果您正苦于以下问题:TypeScript subdirs函数的具体用法?TypeScript subdirs怎么用?TypeScript subdirs使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了subdirs函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
dir.files("./", function(err, files) {
console.log(files);
});
dir.files("./", function(err, files) {
// sort descending
files.reverse();
// include only certain filenames
files = files.filter(function(file: any) {
return ['allowed', 'file', 'names'].indexOf(file) > -1;
});
// exclude some filenames
files = files.filter(function(file: any) {
return ['exclude', 'these', 'files'].indexOf(file) === -1;
});
});
dir.subdirs("./", function(err, subdirs) {
console.log(subdirs);
});
dir.paths("./", function(err, paths) {
console.log('files:\n', paths.files);
console.log('subdirs:\n', paths.dirs);
});
dir.paths("./", true, function(err, paths) {
console.log('paths:\n', paths);
});
示例2: hostRule
dir.subdirs(rootDir + '/rules/', (err, subdirs) => {
const hostRule = (ruleName, subdir, subdirS) => {
dir.files(subdir, (err, files) => {
if (err) {
throw err;
}
let relativeDir = '/gamerules/';
for (let i = 2; i < subdirS.length; i = i + 1) {
relativeDir += subdirS[i] + '/';
}
files.forEach((file) => {
const fileS = file.split(/[\/\\]/);
const route = relativeDir + fileS[fileS.length - 1];
console.log('Setting route ' + route + ' => ' + file);
app.get(route, (req, res) => {
res.sendFile(file);
});
});
});
}
subdirs.forEach((subdir) => {
const relativeDir = subdir.replace(rootDir, '');
const subdirS = relativeDir.split(/[\/\\]/);
const ruleName = subdirS[2];
console.log('Hosting rule ' + ruleName + ' path:' + relativeDir);
hostRule(ruleName, subdir, subdirS);
});
});