function F = copyToPerHostFolder(pool, name, filesOrFolders)
% parallel.pool.copyToPerHostFolder - copies files and folders to per-host folders
%    F = parallel.pool.copyToPerHostFolder(POOL, SUBFOLDER, FILESORFOLDERS) copies
%    files and folders listed in cell array FILESORFOLDERS to per-host
%    sub-folder SUBFOLDER. Each file listed in FILESORFOLDERS will be placed
%    directly into the per-host folder SUBFOLDER. Each folder listed in
%    FILESORFOLDERS will have the trailing portion of the folder structure
%    replicated.
%
%    Examples:
%    Consider a client-side folder structure
%      /home/user/someFiles/my_model.slx
%      /shared/project/someData/data1.mat
%      /shared/project/someData/subdir/data2.mat
%    Copy files to the per-host folder:
%      p = gcp();
%      subdir = 'testing';
%      f1 = parallel.pool.createFolder(p, subdir);
%      f2 = parallel.pool.copyToPerHostFolder(p, subdir, ...
%          {'/home/user/someFiles/my_model.slx', ...
%           '/shared/project/someData'});
%    Then, on successful completion of f2, the following files will
%    exist on the per-host worker folders:
%      <per-host-root>/testing/my_model.slx
%      <per-host-root>/testing/someData/data1.mat
%      <per-host-root>/testing/someData/subdir/data1.mat

% Copyright 2014-2017 The MathWorks, Inc.

% Convert any string inputs to character vectors
[name, filesOrFolders] = convertStringsToChars(name, filesOrFolders);

if ~iscell(filesOrFolders)
    filesOrFolders = {filesOrFolders};
end

validateattributes(pool, {'parallel.Pool'}, {'scalar'});
validateattributes(name, {'char'}, {'row', 'nonempty'});
validateattributes(filesOrFolders, {'cell'}, {'row'});
F = copyToPerHost(parallel.internal.pool.FolderManagement.getForPool(pool), ...
                  name, filesOrFolders);
end
