copy.m 928 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function res = copy(this, newname)
  2. % Method for copying a dataset
  3. % FORMAT res = copy(this, fname)
  4. %
  5. % fname can be
  6. % - path\filename -> data copied and renamed
  7. % - path -> data copied only
  8. %__________________________________________________________________________
  9. % Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
  10. % Vladimir Litvak
  11. % $Id: copy.m 5025 2012-10-31 14:44:13Z vladimir $
  12. [p, f] = fileparts(newname);
  13. if ~isempty(p)
  14. if ~exist(p,'dir'), mkdir(p); end;
  15. else
  16. p = path(this);
  17. end
  18. if isempty(f)
  19. f = fname(this);
  20. else
  21. f = [f '.mat'];
  22. end
  23. if strcmpi(fullfile(this), fullfile(p, f))
  24. res = this;
  25. return;
  26. end
  27. %-Copy dataset (.mat and .dat)
  28. %--------------------------------------------------------------------------
  29. new = clone(this, fullfile(p, f));
  30. [r, msg] = copyfile(fnamedat(this), ...
  31. fnamedat(new), 'f');
  32. if ~r
  33. error(msg);
  34. res = [];
  35. else
  36. res = new;
  37. end