I Load 10,000 image files from internet site and i save it in the folder to use it in my project (image retrieval system ), now i need to rename image file in a sequential name like (image1,image2,image3,....image10000) , any one can help me...
I would like to inform you that I used matlab in my work
thank
One thing you'll want to keep in mind is exactly how the format of the number part of the file name will look, as this can sometimes affect the ordering of the files in the directory. For example, using the naming convention you give above will sometimes result in a sort order like this:
image1.jpg
image10.jpg
image11.jpg
image2.jpg
image3.jpg
...
This isn't generally what you would want. If you instead pad the number with zeroes up to the maximum number size (in your case 5 digits), the sort order should be maintained better in the directory:
image00001.jpg
image00002.jpg
image00003.jpg
....
To create file names like this, you can use the SPRINTF function. Here's some sample code that renames all the .jpg files in a directory in this way:
dirData = dir('*.jpg'); %# Get the selected file data
fileNames = {dirData.name}; %# Create a cell array of file names
for iFile = 1:numel(fileNames) %# Loop over the file names
newName = sprintf('image%05d.jpg',iFile); %# Make the new name
movefile(fileNames{iFile},newName); %# Rename the file
end
The above code also uses the DIR and MOVEFILE functions (as mentioned in the other answers).
rename a file in matlab:
movefile('myfile.m','myfile2.m')
and you need to get all files in a folder, try something like:
filelist = dir('*.jpg');
You could use matlab's "movefile" function (first parameter is the source name, second parameter is the destination) or when you write the image originally you could specify the file e in your imwrite command.
Either way, I suspect you'll need to loop through a direcory listing, this can be done with either the "dir" or "ls" functions.
I got one line shorter
datafiles = dir('*.jpeg');
for i = 1:length(datafiles)
fileOut = strrep(datafiles(i).name, '0000.jpeg', '.jpeg');
movefile(datafiles(i).name, fileOut);
end