How to use waitbar while copying images from folders and subfolders

1 次查看(过去 30 天)
I have stored the images in a folder named 'dataset' , which contains subfolders as 'red' , 'brown' , 'black' , and each folder contains abt 50 images. I want to copy these images into a folder named 'testing data' , meanwhile , while copying the images I want to display a waitbar which shows the copying process , I did try out somethings but couldn't succeed .The code is as :
clear all
clc
M_dir = 'C:\Users\Dell\Documents\MATLAB\dataset\';% source directory
D_dir = 'C:\Users\Dell\Documents\MATLAB\testing_data\';
files = dir(M_dir);
dirFlags = [files.isdir];
subFolders = files(dirFlags);
mkdir testing_data
for k = 1 :length(subFolders)
if any(isletter(subFolders(k).name))
c_dtry = strcat(M_dir,subFolders(k).name);
fileList = getAllFiles(c_dtry);
h = waitbar(0,'Please wait...');
for i=1:150
for n1 = 1:length(fileList)
[pathstr,name,ext] = fileparts(fileList{n1})% file type
Im = imread(fileList{n1});
f=str2num(name);
if(f>=1 & f<=50)
baseFileName = strcat(name,ext);
imwrite(Im, fullfile(D_dir, baseFileName));
elseif(f>=59 & f<=83)
baseFileName = strcat(name,ext);
imwrite(Im, fullfile(D_dir, baseFileName));
elseif(f>=109 & f<=133)
baseFileName = strcat(name,ext);
imwrite(Im, fullfile(D_dir, baseFileName));
end
end
waitbar(i/80,h)
end
end
end
Basically ,I have tried in many places but could not find the answer, I would appreciate it if you could help me to solve this problem !!! Thank you :)

采纳的回答

Rik
Rik 2019-2-26
What I would do is first make a list of all sources and targets, and then do the actual copying in a loop like this
h_wait=waitbar(0,'copying...');
N=numel(sources);
for n=1:N
copyfile(sources{n},destinations{n})
waitbar(n/N,h_wait)
end
That should work
  3 个评论
Rik
Rik 2019-3-19
What code did you use to generate the sources cell array and the destinations cell array? And what specific error message are you getting?

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by