MATLAB: Changing the names of text files in a directory

renaming files

I have 400 files in a directory called NAIC that are named like this: 7488311dbf9821f9.txt.001 is it possible to rename using matlab to naic1.txt till naic400.txt?

Best Answer

Copy all your files to a folder named '\test' under current folder, run the following code.
Folder=fullfile(pwd,'test');
Files=dir(Folder);
for k=1:length(Files)
[PathStr,FileName,FileExt]=fileparts(Files(k).name);
if length(FileExt)==4 % Exclude folder . and folder ..
movefile(fullfile(Folder,Files(k).name),...
fullfile(Folder,['naic',FileExt(2:end),'.txt']));
end
end