i have few images, i want to create folders, and names of folders should be identical to images. and want to save those images in folders having identical names.
1 view (last 30 days)
Image Analyst on 2 Dec 2017
% Specify the folder where the files live.
myFolder = 'D:\My Pictures\Misc'; % Wherever...
% Check to make sure that folder actually exists. Warn user if it doesn't.
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.PNG'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
% Create a folder with the base file name
[~, baseFileNameNoExt, ~] = fileparts(baseFileName);
outputFolder = fullfile(myFolder, baseFileNameNoExt);
if ~exist(outputFolder, 'dir')
fprintf('Created folder : %s\n', outputFolder);
% Prepare output filename
outputFileName = fullfile(outputFolder, baseFileName);
% Copy file to that folder
fprintf(' Copied %s to the folder called %s.\n', baseFileName, outputFolder);