moving files from one directory to multiple folders

4 ビュー (過去 30 日間)
andres nevarez
andres nevarez 2016 年 6 月 30 日
回答済み: Image Analyst 2016 年 6 月 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 Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by