Fastest way to copy files on Windows

14 次查看(过去 30 天)
Joe_Z
Joe_Z 2020-5-22
评论: Rik 2020-5-22
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
% 1) Copy entire main folder
copyfile('driveA:\main_folder', 'driveB:\main_folder');
% 2) parallel copy the subfolders
subfolders = dir('driveA:\main_folder\*'); % ignoring . and .. for now
parfor i = 1:length(subfolders)
copyfile(fullfile(subfolders(i).folder, subfolder(i).name), ...
fullfile('driveB', subfolder(i).name));
end
% 3) parallel copy every individual file
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
  1 个评论
Rik
Rik 2020-5-22
About your second question: that depends on the storage medium you're using. Most drives will use some form of caching. If the files are still in the cache, the writing will be much faster.
I doubt there will be much difference between these three methods, although the second and third might trigger multiple threads of the file transfer, which would speed up the copying.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by