Question

I have 200 JPEG images numbered from 1200 to 1399. How do I change their names from 1200.jpg-1400.jpg to 1.jpg-200.jpg, while keeping the original order of the image names?

Was it helpful?

Solution

This is a problem which can be tackled more efficiently in bash or other shell scripting languages. Probably, it can even be solved just via a single shell find.

Anyway, matlab can also do the job.

Consider this.

list = dir('./stack*.png'); % # assuming the file names are like stack1200.jpg

offset = -1200;  # % numbering offset amount

for idx = 1:length(list)   % # we go through every file name

    name = list(idx).name;   
    number = sscanf(name,'stack%f.png',1);   % # we extract the number
    movefile(name,['stack' num2str(number + offset) '.png' ]);   % # we rename the file.

end

OTHER TIPS

I have find this solution which is quiet straightforward.

Pathfold= ('Path\to\images\');
dirData = dir('path\to\images\*.jpg'); 
fileNames = {dirData.name}; 
for i = 1:size(fileNames)  
    newName = sprintf('%d.jpg',i);
    movefile(fileNames{i},[Pathfold , newName]) %# Rename the file
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top