javascriptnode.jsfilesystemsfs-extra

Why can't I delete the directory that I've created using fs-extra in Electron?


So I have a problem where after I create a directory in my windows computer, I'd like to delete the folder, but whenever i tried to delete the Folder this error come's out.

unable to delete the folder

So, here's my code,

function createFolders(dir) {
            try {
                const newPath = path.resolve(dir, 'ImageData ');
                fs.ensureDirSync(newPath)
                for (let i = 0; i < this.Folders.length; i++) {
                    const otherFolder = path.resolve(newPath, this.Folders[i]);
                    fs.ensureDirSync(otherFolder)
                }
                return newPath
            } catch (e) {
                errorMessage('Error: Folder making error')
                return undefined
            }
        }

I've also tried it with normal fs and mkdirp which ended with the same issue. And I am not sure if this is helpful but I also copied some files into the created folder using fs-extra copySync() function. Not really sure if that will affect anything.

Or am I missing a step, cause I am fairly new to fs and I have very little knowledge on it.

Many Thanks in advance.


Solution

  • There is a leftover whitespace in

    'ImageData ' 
    

    Delete it and it should work.