moving files from one directory to multiple folders

4 visualizaciones (últimos 30 días)
andres nevarez
andres nevarez el 30 de Jun. de 2016
Respondida: Image Analyst el 30 de Jun. de 2016
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.

Respuestas (1)

Image Analyst
Image Analyst el 30 de Jun. de 2016
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);

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by