How to use waitbar while copying images from folders and subfolders

2 ビュー (過去 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 :)

採用された回答

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?
Blessy Bestus
Blessy Bestus 2019 年 3 月 19 日
Thank you sir !!! Got the problem solved :) Thanks a lot sir :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by