我想使用MATLAB例程将一些文件从一个文件夹复制到另一个文件夹。我的目标是每4个文件从初始文件夹复制一个文件到第二个文件。 我的文件看起来像这样:
aa-dd-cc-11-01.txt
aa-dd-cc-11-02.txt
aa-dd-cc-11-03.txt
aa-dd-cc-11-04.txt
aa-dd-cc-11-05.txt
aa-dd-cc-11-06.txt
aa-dd-cc-11-07.txt
aa-dd-cc-11-08.txt
aa-dd-cc-11-09.txt
我想在第二个文件夹中复制:
aa-dd-cc-11-01.txt
aa-dd-cc-11-04.txt
aa-dd-cc-11-08.txt
其中aa-dd-cc-11-08
是文件名,.txt
是扩展名
答案 0 :(得分:3)
source = dir('mysourcedir');
% remove directories from listing
source = source(~[source.isdir]);
% pull every 5th file
subset = source(1:5:end);
for i = 1:length(subset)
% copy source file to destination
% use movefile in place of copyfile if you want to move instead
% of copy
copyfile(fullfile('mysourcedir', subset(i).name), ...
fullfile('mydestdir', subset(i).name));
end