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

13 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2022-4-10
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

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by