Skip to content

Instantly share code, notes, and snippets.

@Edgar-P-yan
Last active July 9, 2019 01:21
Show Gist options
  • Save Edgar-P-yan/6362376bcb16ae6cd97f5d4768cf0019 to your computer and use it in GitHub Desktop.
Save Edgar-P-yan/6362376bcb16ae6cd97f5d4768cf0019 to your computer and use it in GitHub Desktop.
const { promisify } = require('util');
const fs = require('fs');
const path = require('path');
const readDir = promisify(fs.readdir);
const lstat = promisify(fs.lstat);
async function traverseDir(dir, first) {
// рекурсивный перебор файлов
const files = await readDir(dir);
try {
await Promise.all(
files.map(file =>
(async () => {
try {
const fullPath = path.join(dir, file);
const stats = await lstat(fullPath);
if (stats.isDirectory()) {
await traverseDir(fullPath);
} else {
console.log(fullPath);
// replace(fullPath);
}
} catch (err) {
return console.log(err);
}
})(),
),
);
} catch (err) {
return console.log('Unable to scan directory: ' + err);
}
}
traverseDir(path.join(__dirname, 'app'))
.then(() => console.log('done'))
.catch(err => console.trace(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment