After rename zip file i could not delete folder in node.js

i have renamed upload file by using like this

fs.rename('xxxxx','xxxxx',function(err)
{

});

after renamed within that callback function i have tried to remove on folder but it is not working ,i have tried like this

fs.rename('xxxxx','xxxxx',function(err)
{

     fs.rmdir('xxxx',function(err)
    {
        if(err)
       {
           console.log('error');
       }else
       {
            console.log('removed');
       }

    });
});

but i am always getting err in console and files also does not removed.how to resolve this ?

You can not remove a folder that has files in it. You need to delete all the files in the folder first.

There's no quick way to delete a whole tree in Node.js. You could, make it a little easier by using node-file-utils. It has a walk function that will traverse subdirectories of a path. You could use that to fairly easily delete all files in a path.

Have you tried to run the command directly?

var exec = require('child_process').exec;
var path = 'path/to/your/folder';
var command = 'rm -rf ' + path;
exec(command, function(error){

});

With your above code, I assume that you have already known the path to your file