Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 1fcf914

Browse files
committed
make async
1 parent f31f01b commit 1fcf914

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/fileTools.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function searchFile (dir, fileName, callback) {
156156

157157
// uses the folderScanSync to DFS and grab absolute paths of all files and folders, deleting folders (deepest first) and moving files to the target
158158
// requires an absolute path for sourcePath and targetFolderPath.
159-
function flattenFolderStructure(sourcePath, targetFolderPath, callback) {
159+
function flattenFolderStructureSync(sourcePath, targetFolderPath, callback) {
160160
return Q.resolve().then(function () {
161161
var output = {
162162
files: [],
@@ -182,6 +182,18 @@ function flattenFolderStructure(sourcePath, targetFolderPath, callback) {
182182
}).nodeify(callback);
183183
}
184184

185+
// 1. Scan Folders, create an object
186+
function flattenFolderStructure(sourcePath, targetFolderPath, callback) {
187+
return folderScan(sourcePath).then(output => {
188+
return Q.all(output.files.map(file => { return fs.promises.rename(file, targetFolderPath + path.parse(file).base)}))
189+
.then(() => {
190+
return Q.all(output.folders.map(folder => {
191+
return fs.promises.rmdir(folder)
192+
}));
193+
});
194+
}).nodeify(callback);
195+
}
196+
185197
// DFS crawl into the folder structure and grab all references.
186198
// output is an object: { files: [], folders: [] }
187199
function folderScanSync(output, directory) {

0 commit comments

Comments
 (0)