tags:

views:

64

answers:

1

I would 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

+3  A: 
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
Mark E
Thank you a lot, it works perfectly !!
seregon