MATLAB Answers

How to use waitbar while copying images from folders and subfolders

3 ビュー (過去 30 日間)
Blessy Bestus
Blessy Bestus 2019 年 2 月 26 日
コメント済み: Blessy Bestus 2019 年 3 月 19 日
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 :)

  0 件のコメント

サインイン to comment.

採用された回答

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 件のコメント

Blessy Bestus
Blessy Bestus 2019 年 3 月 19 日
Thanlk you sir . Sir I did try to run the code , but it is giving me error for brackets , did do some changes , but its not working . Sir please help me to figure it out . Thank you sir:)
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?
Blessy Bestus
Blessy Bestus 2019 年 3 月 19 日
Thank you sir !!! Got the problem solved :) Thanks a lot sir :)

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。

タグ


Translated by