필터 지우기
필터 지우기

How to save multiple images in the same folder?

조회 수: 1 (최근 30일)
Sahar abdalah
Sahar abdalah 2016년 1월 1일
댓글: Walter Roberson 2016년 1월 4일
hello, I have several images that are saved in different folders and I want to arrange theses images in a single folder. please, any suggestion of matlab code? thanks in advances

채택된 답변

Image Analyst
Image Analyst 2016년 1월 1일
Perhaps use my demo. In the middle of the loop is where you would stick a call to copyfile() or movefile().

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 1일
The function you supply would movefile()
Watch out for duplicate file names! Watch out for bugs while you get the code working...
If I were developing the code, I would refrain from moving the files unless I had good reason. I would either copy the files or I would create links to the files.
  댓글 수: 2
Sahar abdalah
Sahar abdalah 2016년 1월 1일
thank you for your reply, but I am new in matlab and I did not understand the importance of this link in the resolution of my problem. simply, I have images with different names and are stored in multiple folders, my goal is to copy all images in a single folder. I have a folder: flowers that contain 12 others folders (category 1, category 2, ......, category 12). and each folder contain a list of images corresponding to the category of flowers. my goal is to save these images in a new folder called flowerCategory. Any idea please for matlab code?
Walter Roberson
Walter Roberson 2016년 1월 4일
sourcedir = fullfile(pwd, 'flowers');
destdir = fullfile(pwd, 'flowerCategory');
if ~exist(destdir,'dir')
[success, message, messageid] = mkdir(destdir);
if ~success
error(messageid, sprintf('Failed to create directory "%s" because "%s"', destdir, message) );
end
end
%find the potential source directories
dinfo = dir( fullfile(sourcedir, 'category*') );
%remove everything that is not a directory
dinfo(~[dinfo.isdir]) = [];
for J = 1 : length(dinfo) %for each source directory
thisdir = fullfile(sourcedir, dinfo(J).name);
%find potential files in directory
finfo = dir( thisdir );
%get rid of the things that are not files
finfo([finfo.isdir]) = [];
for K = 1 : length(finfo) %for each file in directory
thisfile = fullfile(thisdir, finfo(K).name );
%make a copy of it
copyfile(thisfile, destdir);
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by