MATLAB: Renaming files in a folder

rename

Hello,
I'm written the following code to rename files in a folder. However, for whatever reason it is not working. Any idea where I've gone wrong?
I assume the program is self-explanatory, but let me know if you need any clarifications on the task.
function renameFiles
path=('D:\Documents and Settings\Administrator\Desktop\Data 31052012\75mj\all times\');
files=dir(path)
prefix=('75mJ');
time=0;
for id=3:24;
newName=([prefix num2str(time) 'ns'])
movefile(files(id).name, sprintf('%s.bmp',newName));
time=time+2;
end
Thanks!

Best Answer

The directory name is not included in the .name field returned by dir(). You need to add it back on.
movefile( fullfile(path, files(id).name), fullfile(path, sprintf('%s.bmp',newName)) );