开发者

Copy one file every 5 files from a folder to another one using MATLAB

I wo开发者_如何学编程uld like to copy some files from a folder to another folder using MATLAB routines. My goal is to copy one file every 4 files from the initial folder to the second one. My files look like this:

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

And I would like to copy in the second folder, only:

aa-dd-cc-11-01.txt
aa-dd-cc-11-04.txt
aa-dd-cc-11-08.txt

where aa-dd-cc-11-08 is the file name and .txt is the extension

could you help me to write a routine for this, please? thank you in advance


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜