MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

How to use waitbar while copying images from folders and subfolders

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.

タグ

1 件の回答

回答者: 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 件のコメント

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
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?
Thank you sir !!! Got the problem solved :) Thanks a lot sir :)

サインイン to comment.



Translated by