Skip to main content
Silly-V
Legend
Nov 7, 2018 8:20 AM UTC
Question

Delete folder

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

guntramp26642460
Inspiring
Feb 3, 2023 3:10 PM UTC

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?!

 

 

Translate
guntramp26642460
Inspiring
Feb 3, 2023 3:13 PM UTC

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

Translate
Trevor:
Legend
Nov 7, 2018 8:24 AM UTC

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);
 
}
};

Translate
Silly-V
Silly-VAuthor
Legend
Nov 7, 2018 1:21 PM UTC

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.

Translate
Trevor:
Legend
Nov 7, 2018 1:27 PM UTC

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.

Translate