There's no easy way to do it, but nothing stops you from manually checking if the folder exists and then adding it if you need to, then copying files from inside to the new one:
You can check if a list item is a folder by checking its content type (folders will be "Folder")...
To get the content type you need to select and expand ContentType on each item with a URI like this:
_api/web/lists/getbytitle('Documents')/Items(7)?select=Title,ContentType&$expand=ContentType
Then you can use data.ContentType.Name to get the name of the content type
I'll also throw in here that if you just don't want to support copying folders and don't want your script to die, you can just tell the user they selected a folder by checking the item's content type like this and suggesting they only pick files
...If you decide you do want to implement though, you can create a folder using the REST API like this:
function createFolderAsync(newFolderSiteRelativeUrl) {
var reqData = JSON.stringify({ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': newFolderSiteRelativeUrl });
return $.ajax({
url: "../_api/web/folders",
type: "POST",
data: reqData,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $('#__REQUESTDIGEST').val(),
}
});
}
(function () {
$('#yourButton').click(function() {
createFolderAsync('Shared Documents/restTest').done(function () {
console.log('do some other stuff now...');
}).fail(function (jqXHR) {
console.log(jqXHR.responseText);
});
})
}());
It doesn't seem to matter if you 'create' a folder that already exists, it doesn't overwrite existing stuff.
A note on the new folder url: as explained in an answer from Vadim on this question, you'll need to use the right URL path for the folder (and not, for example, the internal library name where you want to add it).
Then you would need to go get all the files in that folder (and maybe the other folders recursively?) and copy them to the new destination...
I would just alert the user they can't pick folders and leave it at that, but I see you already had that battle! :) At the very least you should let them know the time cost for doing this instead of other things.