Fastest way to copy files on Windows

18 visualizzazioni (ultimi 30 giorni)
Joe_Z
Joe_Z il 22 Mag 2020
Commentato: Rik il 22 Mag 2020
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 Commento
Rik
Rik il 22 Mag 2020
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Parallel Computing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by