C # example of source code for bulk file renaming Tool
If there is reprint please indicate the source: http://www.cnblogs.com/flydoos/archive/2011/10/29/2228300.html
C # example of source code for bulk file renaming Tool
Today, someone in the group asked a question about batch renaming, so I will write a demo. Let's take a look at what I need. No difficulty. paste the source code directly, and attach the source code attachment of the vs2010 project. I hope you can point it out so that it can be corrected in the future. (The core is file. Move (), haha)
I am learning about WPF. I hope to send me a copy of anyone who has prepared an electronic reader, exported/imported PDF, Excel, and word for WPF. Thank you. Email: flydoos@vip.qq.com
//////////////////////////////////////// //////////////////////////
//Author: between Niu A and Niu C
//Q: 1046559384 C #/Java technology exchange group: 96020642
//Weibo:Http://weibo.com/flydoos
//Blog:Http://www.cnblogs.com/flydoos
//Date: 2011-10-29
//////////////////////////////////////// //////////////////////////
UsingSystem;
UsingSystem. Windows. forms;
UsingSystem. IO;
NamespaceFilerename
{
Public Partial ClassMainform: Form
{
PublicMainform ()
{
Initializecomponent ();
}
Private Void Btnopenpath_click ( Object Sender, eventargs E)
{
Folderbrowserdialog F1 = New Folderbrowserdialog ();
If (F1.showdialog () = dialogresult. OK)
{
Txtpath. Text = f1.selectedpath;
}
}
Private Void Btnrename_click ( Object Sender, eventargs E)
{
If (Txtpath. Text! ="" )
{
If (Txtnew. Text! = "" )
{
String Stroldpart = txtold. Text. Trim ();
String Strnewpart = txtnew. Text. Trim ();
Datetime starttime = datetime. now;
Try
{
Directoryinfo di = New Directoryinfo (txtpath. Text );
Fileinfo [] filelist = Di. getfiles ( " *.* " );
String Strfilefolder = txtpath. text;
Int I = 0 ;
Int Totalfiles = 0 ;
Foreach (Fileinfo fiIn Filelist)
{
String Stroldfilename = Fi. Name;
String Strnewfilename = Fi. Name. Replace (stroldpart, strnewpart );
String Strnewfilepath = @ strfilefolder + " \\ " + Strnewfilename;
Filelist [I]. moveTo (@ strnewfilepath );
Totalfiles + =1 ;
Lstfiles. Items. Add ( " File Name: " + Stroldfilename + " Renamed " + Strnewfilename + "" );
I + = 1 ;
}
Datetime endtime = datetime. now;
Timespan Ts = endtime-starttime;
TEXT = ( " Total time consumed: " + Ts. Hours + " Hour " + Ts. minutes + " Minute " + Ts. seconds + " Seconds " + Ts. milliseconds + " Millisecond " );
}
Catch
{
MessageBox. Show ( " The path is invalid! " );
}
}
Else
{
MessageBox. Show ( " No matching characters " );
}
}
Else
{
MessageBox. Show ( " Select a path first! " );
}
}
}
}
CompleteCodeDownload: Network Disk download 1 Network Disk download 2 backup download 3
If the vs2010 project cannot be opened, download it hereVisual Studio version Conversion Tool 1.1.