How to truncate/modify a file name
Mostra commenti meno recenti
Hi everyone,
The question pertains to modifying file names during a batch processing operation. Basically, I would like to truncate a certain portion of the file name and use that as the output name of the processed file. Please see the code below and the comments, outlining the question:
clc
clear all
files = dir('*.JPG');
filePrefix_cr = 'Cropped ';
% For example, let's use a file name like: S-0281 AB196C3 View 3.jpg.
% What I would like to have for a file name is: Cropped AB196C3 View 3.jpg.
% The result from this code is: Cropped S-0281 AB196C3 View 3.jpg.
% How do I truncate the S-0281, i.e. the first 6 characters of the file
% name, prior to introducing 'Cropped'?
for k = 1:numel(files)
rgb = imread(files(k).name);
% Runs a file modification process, e.g. a cropping process.
imwrite(rgb, [filePrefix_cr files(k).name]);
end
Thanks in advance for all the help and have a good week.
Regards
Risposta accettata
Più risposte (2)
Categorie
Scopri di più su Title in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!