Last active
July 9, 2019 01:21
-
-
Save Edgar-P-yan/6362376bcb16ae6cd97f5d4768cf0019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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