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

2 ビュー (過去 30 日間)
Ashfaq Ahmed
Ashfaq Ahmed 2022 年 4 月 10 日
コメント済み: Voss 2022 年 4 月 10 日
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
  2 件のコメント
Voss
Voss 2022 年 4 月 10 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by