Click here to Skip to main content
15,918,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have folder that contain images how can i rename images From 0 to the number of images ,how can i do loop to rename images
Posted

in the programe extract vedio to frams the frames saved in folder how refresh folder after saving and i want to rename the frames with numer order .
thanks
 
Share this answer
 
C#
DirectoryInfo d = new DirectoryInfo(@"E:\Images\");
FileInfo[] infos = d.GetFiles("*");
int i = 0;
foreach (FileInfo f in infos)
{
    i = i + 1;
    File.Move(f.FullName, Path.Combine(f.Directory.ToString(), Convert.ToString(i)) + f.Extension);
}
 
Share this answer
 
Comments
NeptuneHACK! 9-Feb-12 0:19am    
my 5
rafef Ali 9-Feb-12 17:19pm    
Error 1 'System.Windows.Forms.MainMenu' does not contain a definition for 'Move' and no extension method 'Move' accepting a first argument of type 'System.Windows.Forms.MainMenu' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\aaa\Desktop\New Folder (2)\project\5555510\555\555\Program.cs 441 22 555
ihave this problem
santhosh-padamatinti 9-Feb-12 23:38pm    
Have you added
"using System.IO;" this namesapce in program.

Also You are working with C drive, So please run your program as administrator mode.
rafef Ali 10-Feb-12 18:32pm    
ok Thank you very much, but this new problem appears
(The process cannot access the file because it is being used by another process)
MCY 11-Feb-12 15:30pm    
close the opened images before renaming?
C#
DirectoryInfo di = new DirectoryInfo("Folder_of_interest");

foreach (FileInfo fi in di.GetFiles())
{
    fi.MoveTo("new_file_name");
}


That should get you started.
 
Share this answer
 
Comments
NeptuneHACK! 9-Feb-12 0:19am    
my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900