C # example of source code for bulk file renaming Tool

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.