MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   使用MATLAB将每5个文件中的一个文件从一个文件夹复制到另一个 (https://www.labfans.com/bbs/showthread.php?t=23988)

poster 2019-12-10 20:48

使用MATLAB将每5个文件中的一个文件从一个文件夹复制到另一个
 
我想使用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是扩展名

你能帮我写一个例程吗?先感谢您



[B]回答:[/B]

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

[url=https://stackoverflow.com/questions/3914513]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:21

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.