Last active
January 7, 2019 04:11
-
-
Save thejohnfreeman/00612fd3789e5a7303604d4ef77cce96 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
| async function () { | |
| const files = await fs.readdir('a'); | |
| await Promise.all(files.map(async (filename) => { | |
| const data = await fs.readFile(filename); | |
| await fs.writeFile('b/' + filename, data); | |
| console.log(filename); | |
| })); | |
| }(); |
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
| // Copy every file in directory `a` to directory `b`. | |
| fs.readdir('a', function (error, files) { | |
| if (error) throw error; | |
| for (var i = 0; i < files.length; ++i) { | |
| var filename = files[i]; | |
| fs.readFile(filename, function (error, data) { | |
| if (error) throw error; | |
| fs.writeFile('b/' + filename, data, function (error) { | |
| if (error) throw error; | |
| console.log(filename); | |
| }); | |
| }); | |
| } | |
| }); |
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
| async(function*() { | |
| const files = yield fs.readdir('a'); | |
| yield Promise.all(files.map(async(function* (filename) { | |
| const data = yield fs.readFile(filename); | |
| yield fs.writeFile('b/' + filename, data); | |
| console.log(filename); | |
| }))); | |
| })(); |
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
| fs.readdir('a') | |
| .then(files => Promise.all( | |
| files.map(filename => | |
| fs.readFile(filename) | |
| .then(data => fs.writeFile('b/' + filename, data)) | |
| .then(() => console.log(filename)) | |
| ) | |
| )) | |
| .catch(error => throw error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment