Delete a file in use by the renderer


#1

Hello I am trying to do a video preview with electron.

In order to do that I have to load a mp4 file into the DOM. At a tiem I need to delete the folder that contains the video. But as the video is in use by the DOM the operating system (Windows 7) does not let me delete it.

I am removing the video file form the DOM with the following command:
var removeAssesFromUsage = function()
{
$(’#videoPreview’).remove();

    $('#videoPreviewArea').children().filter("video").each(function()
    {
        this.pause(); // can't hurt
        delete this; // @sparkey reports that this did the trick (even though it makes no sense!)
        $(this).remove(); // this is probably what actually does the trick
    });
    $('#videoPreviewArea').empty();
};

I am using rimraf and the error I get is:
error: ENOTEMPTY: directory not empty, rmdir ‘C:\Users\machine\Desktop\videopackager-win32-x64\temp\unpack’(…)

I already tried to delete the contents before I delete the folder without using rimraf.
And it still gives me the same error.
fileManager.prototype.deleteFolderRecursive = function(path)
{
var result = false;

    var self = this;
    try
    {
        if (fs.existsSync(path))
        {
            fs.readdirSync(path).forEach(function (file)
            {
                var curPath = path + "/" + file;
                if (fs.lstatSync(curPath).isDirectory())
                { // recurse
                    self.deleteFolderRecursive(curPath);
                }
                else
                { // delete file
                    fs.unlinkSync(curPath);

                    while(fs.existsSync(curPath))
                    {
                        fs.unlinkSync(curPath);
                    }
                }
            });
            fs.rmdirSync(path);
        }
    }
    catch(e)
    {
        console.log(e);
    }
};

Is there a way to remove a file from DOM in order to be able to delete it from the hard drive?
Thank you…


#2

I have tried a bunch of things and I am having a lot of trouble deleting a file that is in use by the dom (In windows) What is the best way to do this. (Is there a method to check if the file is in use?)