what you're missing is
path = 'C:\temps (IT do not delete)\matlabAnswers\dirtest\';
dirData = dir(strcat(path,'*.wav'));
fileNames = {dirData.name};
for iFile = 1:numel(fileNames)
newName = strcat('hole',fileNames(iFile),sprintf('%d',iFile));
movefile(fileNames{iFile},cell2mat(newName));
end
i used wav files as i had a directory full of junk wav files. just change to png.. so the initial problems are:
- in the move file the newName was a cell. that is why it asked for a string.
- in the sprintf you were printing the number as a string. so it made it an empty space after the new name.
I'm not exactly sure if you want to put the numbering after the .wav#. perhaps you wanted holeFilename#.wav
then you substitute the for loop with something like this
for iFile = 1:numel(fileNames)
newName = strcat('hole',fileNames{iFile}(1:end-4),sprintf('%d',iFile),'.wav');
movefile(fileNames{iFile},newName);
end
Best Answer