* @class elFinder command "duplicate"
* Create file/folder copy with suffix "copy Number"
* @author Dmitry (dio) Levashov
elFinder.prototype.commands.duplicate = function() {
this.getstate = function(select) {
var sel = this.files(select),
filter = function(files) {
return $.grep(files, function(f) {
fres = fres && f.read && f.phash === fm.cwd().hash && ! fm.isRoot(f)? true : false;
return cnt && fm.cwd().write && filter(sel).length == cnt ? 0 : -1;
this.exec = function(hashes) {
files = this.files(hashes),
error && fm.error(error);
$.each(files, function(i, file) {
if (!file.read || !fm.file(file.phash).write) {
return !dfrd.reject(['errCopy', file.name, 'errPerm']);
if (dfrd.state() == 'rejected') {
data : {cmd : 'duplicate', targets : this.hashes(hashes)},
notify : {type : 'copy', cnt : cnt},
inbuffer : {msg: fm.i18n(['complete', fm.i18n('cmdduplicate')])}