我想使用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是扩展名
你能帮我写一个例程吗?先感谢您
回答:
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
更多&回答...