Rename file in c#

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

Hi,

I have more than 1000 photos in my system but with very untidy name.
Im trying to create a program through which i can rename the file.

I have seen the examples on net an forums, but the only solution seems
to be with moving the file with different name.

I don't want to move the file but just want to rename it..

How this can be done.

Please help. Thanks for replying me.
 
I have more than 1000 photos in my system but with very untidy name.
Im trying to create a program through which i can rename the file.

I have seen the examples on net an forums, but the only solution seems
to be with moving the file with different name.

I don't want to move the file but just want to rename it..

Renaming a file basically *is* moving it in almost all situations.
Have you tried using File.Move and had issues with it?

Jon
 
jack said:
Hi,

I have more than 1000 photos in my system but with very untidy name.
Im trying to create a program through which i can rename the file.

I have seen the examples on net an forums, but the only solution seems
to be with moving the file with different name.

I don't want to move the file but just want to rename it..

How this can be done.

There is no rename command in the file system. You use the move command
to rename a file.

It's been that way ever since DOS 2.0, when folders where introduced.
 
Yes. I have created program which moves the files with the new name in
new subfolder, which is working perfectly fine below is the code.


private void fnFile()
{
DirectoryInfo di = new DirectoryInfo(@"D:\Temp");
FileInfo[] fiArr = di.GetFiles("*.rtf");
DirectoryInfo ditemp = di.CreateSubdirectory("testme");
int iCtr = 0;
foreach (FileInfo fri in fiArr)
{
fri.MoveTo(@"D:\Temp\testme\" + fri.Name);
iCtr++;
}
}


Just now i tried to move the file in the same folder with different
(New) name and worked properly. and the functionality is also like
renaming the filename. internally i think its same as renaming the
file.
below is my amended code


private void fnFile()
{
DirectoryInfo di = new DirectoryInfo(@"D:\Temp\testme\");
FileInfo[] fiArr = di.GetFiles("*.rtf");
int iCtr = 0;
foreach (FileInfo fri in fiArr)
{
MessageBox.Show(fri.FullName.ToString(), "File
Manager", MessageBoxButtons.OK);
fri.MoveTo(@"D:\Temp\testme\" + "RtfFiles New(" + iCtr
+ ").rtf");
iCtr++;
}
}
 
There is no rename command in the file system. You use the move command
to rename a file.

It's been that way ever since DOS 2.0, when folders where introduced.

Yes, but in DOS there was a Rename command so it was a little more
intuitive. The Move command wasn't introduced in MS-DOS until v6

Chris
 
And the rename command (ren) still works in XP from a command prompt

Yes, but in DOS there was a Rename command so it was a little more
intuitive. The Move command wasn't introduced in MS-DOS until v6
 
Chris said:
Yes, but in DOS there was a Rename command so it was a little more
intuitive. The Move command wasn't introduced in MS-DOS until v6

Chris

That's the CLI commands. I am of course talking about int 21h ah=56h. :)
 
Back
Top