MATLAB: Read all files from a folder, edit them and save.

image processing

I have written a code to read image from a folder, edit it's array and save it. How can I do the same for multiple files at once ? All files are named as 'TangoBlack_00000' with the number increasing by 1 for each file. So I have files numbered till 'TangoBlack_00110'. Also can I edit the files directly instead of saving them with different file names ? I have attched the code below:
a=imread('TangoBlack_00009.bmp');
a(33:40,:)=0;
a(153:160,:)=0;
imwrite(a,'TB_09.bmp')

Best Answer

Give the actual file(folderPath1) and write file(WriteDir) folder paths into the code and you should be able to modify and save them to the desired folder with the name you want.
% folderPath1 = actualFile folder
folderPath1 = 'D:\MATLAB\actualFilesFolder';
cd(folderPath1); % path of the folder
% WriteDir = WriteFile Folder
WriteDir = 'D:\MATLAB\WriteFolder';
files1 = dir('**');
files1(1:2) = [];
totalFiles = numel(files1);
for i =1:totalFiles
Fileaddress{i,1}=strcat(folderPath1,'\',files1(i).name);
file{i} = imread(Fileaddress{i,1});
% Edit the file
file{i}(33:40,:)=0;
file{i}(153:160,:)=0;
cd(WriteDir) % go to dir where you want to save updated files
writeFileName = strcat('TB_0',num2str(i),'.bmp');
imwrite(file{i},writeFileName)
cd(folderPath1) % return to actualFile folder
end
% This is assuming you are using a Windows computer, if you have a Mac the folders convention will be slightly different