moving files from one directory to multiple folders

4 次查看(过去 30 天)
Hello all,
I am a first-time poster, long-time reader. I am also new to Matlab.
I have multiple files in one directory. The file names are date_specimen_experiment001xy01.tif. The experiment number changes with a max of 720 (_experiment001xy01,_experiment002xy01,etc). The xy position change with a max of 10 (_experiment001xy01,_experiment001xy02,etc). I want to move files (_experiment001xy01 to _experiment001xy10) into folder 1. I then want to sequentially do this for all 720 experiments. The end product should be 720 folders with 10 files in each folder.

回答(1 个)

Image Analyst
Image Analyst 2016-6-30
Try something like
inputFile = '_experiment001xy01.tif';
[inputFolder, baseFileName, ext] = fileparts(inputFile)
exptNum = str2double(baseFileName(12:14))
outputFolder = fullfile(inputFolder, num2str(exptNum))
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
destinationFile = fullfile(outputFolder, baseFileName);
copyfile(inputFile, destinationFile);

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by