Here is a snippet that can help you to remove a non-empty directory from the server. It’s a recursive function…