When I used this tool, I found the method of renaming a file in C # on the Internet and made one by myself. Although simple, it is quite practical and I can often use it
Just one fileCode:
Code
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
// C # Implementation of batch renaming file codes
// Add file operation space reference
Using System. IO;
Namespace Windowsapplication1
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Private Void Form1_load ( Object Sender, eventargs E)
{
}
Private Void Button#click ( Object Sender, eventargs E)
{
Folderbrowserdialog F1 = New Folderbrowserdialog ();
If (F1.showdialog () = Dialogresult. OK)
{
Textbox3.text = F1.selectedpath;
}
}
Private Void Button2_click ( Object Sender, eventargs E)
{
If (Textbox3.text ! = "" ){
If (Textbox1.text ! = "" )
{
String Stroldfilename;
String Strnewfilename;
String Stroldpart = This . Textbox1.text. Trim ();
String Strnewpart = This . Textbox2.text. Trim ();
String Strnewfilepath;
String Strfilefolder;
Int Totalfiles = 0 ;
Datetime starttime = Datetime. now; // Get Start Time
Try {
Directoryinfo di = New Directoryinfo (textbox3.text );
Fileinfo [] filelist = Di. getfiles ( " *.* " );
Strfilefolder = Textbox3.text;
Int I = 0 ;
Foreach (Fileinfo fi In Filelist)
{
Stroldfilename = Fi. Name;
Strnewfilename = Fi. Name. Replace (stroldpart, strnewpart );
Strnewfilepath = @ Strfilefolder + " \\ " + Strnewfilename;
Filelist [I]. moveTo (@ strnewfilepath );
Totalfiles + = 1 ;
This . Listbox1.items. Add ( " File Name: " + Stroldfilename + " Renamed " + Strnewfilename + "" );
I + = 1 ;
}
Datetime endtime = Datetime. now; // Get End Time
Timespan TS = Endtime - Starttime;
This . Listbox1.items. Add ( " Total time consumed: " + TS. Hours. tostring () + " Hour " + TS. Minutes. tostring () + " Minute " + TS. Seconds. tostring () + " Seconds " + TS. milliseconds. tostring () + " Millisecond " );
}
Catch
{
MessageBox. Show ( " The path is invalid! " );
}
}
Else
{
MessageBox. Show ( " No matching characters " );
}
}
Else
{
MessageBox. Show ( " Select a path first! " );
}
}
}
}