Skip to main content
Silly-V
Legend
November 7, 2018
Question

Delete folder

  • November 7, 2018
  • 2 replies
  • 1390 views

Hello,

I am wondering how to delete a folder (with files in it, if possible) via the window.cep.fs object?

Using deleteFile gives the error "8" ERR_NOT_FILE, and if I try deleteFileOrDirectory(), it says that's not a function.

This topic has been closed for replies.

2 replies

guntramp26642460
Inspiring
February 3, 2023

In my case, it was a folder which could not be deleted by "deleteFile()", returning only {err: 8}.

I thought it was because of a space in the folder name, but from cep.fs we see that error 8 means "not a file"...

So I need to switch to node fs, because cep.fs does not support deleting folders?!

 

 

guntramp26642460
Inspiring
February 3, 2023

Edit: @T@Trevor: 's answer is correct 🙂

Trevor:
Legend
November 7, 2018

This is for NodeJS but the ideas the same

node.js - Remove directory which is not empty - Stack Overflow

var fs = require('fs');
var deleteFolderRecursive = function(path) {
 
if (fs.existsSync(path)) {
  fs
.readdirSync(path).forEach(function(file, index){
  
var curPath = path + "/" + file;
  
if (fs.lstatSync(curPath).isDirectory()) { // recurse
  deleteFolderRecursive
(curPath);
  
} else { // delete file
  fs
.unlinkSync(curPath);
  
}
  
});
  fs
.rmdirSync(path);
 
}
};

Silly-V
Silly-VAuthor
Legend
November 7, 2018

Thanks Trevor, I've got about the same achieved through old-school jsx-based deletion for the current need. However the documentation keeps saying that 'deleteFileOrDirectory' should be working - are you saying that there's actually no possibility with the current (CEP9) window.cep.fs object?

I'm also sure I updated by CSInterface.js to the 9.2.0 version.

Trevor:
Legend
November 7, 2018

No, I've done it using the node fs method and not the window.cep.fs object so I don't know about any changes.