1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Added recursive delete

This commit is contained in:
Ylian Saint-Hilaire 2018-09-25 11:51:40 -07:00
parent dccdf4cc21
commit f04752f1cb
7 changed files with 96 additions and 38 deletions

View file

@ -707,10 +707,9 @@ function createMeshCore(agent) {
break;
}
case 'rm': {
// Remove many files or folders
// Delete, possibly recursive delete
for (var i in cmd.delfiles) {
var fullpath = obj.path.join(cmd.path, cmd.delfiles[i]);
try { fs.unlinkSync(fullpath); } catch (e) { console.log(e); }
try { deleteFolderRecursive(obj.path.join(cmd.path, cmd.delfiles[i]), cmd.rec); } catch (e) { }
}
break;
}
@ -1758,6 +1757,23 @@ function createMeshCore(agent) {
obj.osamtstack.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(x).toString('base64'), function () { });
}
// Delete a directory with a files and directories within it
function deleteFolderRecursive(path, rec) {
if (fs.existsSync(path)) {
if (rec == true) {
fs.readdirSync(obj.path.join(path, '*')).forEach(function (file, index) {
var curPath = obj.path.join(path, file);
if (fs.statSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath, true);
} else { // delete file
fs.unlinkSync(curPath);
}
});
}
fs.unlinkSync(path);
}
};
return obj;
}