I am interested in the fastest way to copy files from one directory to another in MATLAB on Windows platform. I have two questions, one about the quickest way and the second about how memory is used in MATLAB which is why I did not just go ahead and test this myself.
A file structure driveA: main_folder > subfolders > files.ext could be copied by
copyfile('driveA:\main_folder', 'driveB:\main_folder');
subfolders = dir('driveA:\main_folder\*');
parfor i = 1:length(subfolders)
copyfile(fullfile(subfolders(i).folder, subfolder(i).name), ...
fullfile('driveB', subfolder(i).name));
end
files = dir('driveA:\main_folder\*\*.ext')
parfor i = 1:length(files)
path_split = strsplit(files(i).folder, filesep);
path_no_drive = path_split(2:end);
copyfile(fullfile(files(i).folder, files(i).name), ...
fullfile('driveB', path_no_drive, files(i).name));
end
Q1: is there likely to be much difference in performance, particularly between methods 2 and 3?
Q2: the reason I did not test this myself is I have a feeling that when repeating copying files, if repeating a copyfile procedure the files copy much faster if they have been copied recently, as if they were still held in memory. Is this is the case?
Thanks for your help