2010-10-12 21 views
0

我想使用MATLAB例程將某個文件從一個文件夾複製到另一個文件夾。我的目標是將每4個文件從初始文件夾複製到第二個文件。 我的文件是這樣的:使用MATLAB將每5個文件中的一個文件複製到另一個使用MATLAB

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

爲什麼這有-1?我是+1來平衡它。 – 2010-10-12 15:33:40

回答

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 
+0

非常感謝你,它完美的作品! – seregon 2010-10-12 13:37:38

相關問題