Skip to content

Instantly share code, notes, and snippets.

@develar
Last active July 21, 2017 10:01
Show Gist options
  • Save develar/9405c4430fac7e556aaa94cdf3b49a9d to your computer and use it in GitHub Desktop.
Save develar/9405c4430fac7e556aaa94cdf3b49a9d to your computer and use it in GitHub Desktop.
WEB-27555 — without await
'use strict';
const path = require('path');
const fs = require('fs');
const promisify = require('util').promisify;
const unlink = promisify(fs.unlink);
const rmDir = promisify(fs.rmdir);
const readDir = promisify(fs.readdir);
const lstat = promisify(fs.lstat);
const deleteFile = async (dir, file) => {
const filePath = path.join(dir, file);
try {
return deleteDirectory(filePath);
}
catch (e) {
console.error("Handle error")
}
};
const deleteDirectory = async dir => {
let files = await readDir(dir);
await Promise.all(
files.map(file => deleteFile(dir, file))
);
await rmDir(dir);
};
deleteFile("sdfsdf", "wefwe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment