Selecting .tif files from a folder and copy them to another folder

12 views (last 30 days)
Hi!
I have these 34 days folders and each folder contains 3 images (.tif) files. I want to select all these .tif files and copy them to another folder named "All_tif_images".
I wrote down this code but it is not working. Can anyone please tell me what's wrong with the code? Any feedback will be much appreciated!
clear all; close all; clc;
HOME = '/Users/aahmed78/PhD/Data/SWOT/Beaufort Gyre - CalVal/May2015';
day = [1:34];
foldername = 'All_tif_images';
for zz=1:size(day,2)
cd(strcat(HOME,'/Day ',num2str(day(zz))))
file_list = dir('*.tif');
filenumber = length(file_list);
for i = 1:filenumber
filename = file_list(i).name;
cd('..');
copyfile(filename,cd(strcat(HOME,'/All_tif_images')));
end
end

Accepted Answer

Voss
Voss on 10 Apr 2022
clear all; close all; clc;
HOME = '/Users/aahmed78/PhD/Data/SWOT/May2015';
foldername = 'All_tif_images';
foldername = fullfile(HOME,foldername);
file_list = dir(fullfile(HOME,'Day*','*.tif'));
for ii = 1:numel(file_list)
filename = fullfile(file_list(ii).folder,file_list(ii).name);
copyfile(filename,foldername);
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!