Rename a widget

Source: Internet
Author: User
Some time ago I had a lot of tutorials on the Internet, and the file names all started with this character, "come with me to learn XXX", which was very confusing, because the file name is too long, it is too troublesome to manually change the file names when browsing the folder. If there are more than 100 files, let the computer automatically help me change the file name, use C # To write a simple tool.

Column directory Function Private void listdirectory (string path)
{
Directoryinfo dir = new directoryinfo (PATH );
Fileinfo [] files = dir. getfiles ();
String extension = getextension ();

Filelist. Items. Clear ();

Foreach (fileinfo file in files)
{
If (extension! = String. Empty)
{
If (extension. indexof (file. extension. toupper () >=- 1 & file. extension! = String. Empty)
{
Filelist. Items. Add (file. Name );
}
}
Else
{
Filelist. Items. Add (file. Name );
}
}
}

Get Extension Private string getextension ()
{
Stringbuilder sb = new stringbuilder (50 );
Foreach (Control in this. groupbox1.controls)
{
If (control. Tag. tostring (). Equals ("tagextension "))
{
If (control as checkbox). Checked)
{
SB. append (control. Text + ";");
}

}
}
Return sb. tostring ();
}

Rename Method Private void btnrename_click (Object sender, eventargs E)
{
If (MessageBox. Show ("this operation is irreversible. Are you sure you want to continue? "," Ask ", messageboxbuttons. yesno, messageboxicon. Question) = dialogresult. No)
Return;
Fileinfo file;
String prename = this.txt prename. Text. Trim ();
String pre = prename;
Int prelen = (INT) This. prelength. value;

Try
{
For (INT I = 0; I <filelist. Items. Count; I ++)
{
File = new fileinfo (FBD. selectedpath + "\" + filelist. items [I]. tostring ());

If (this. chkauto. Checked) Pre = I. tostring () + "." + prename;
If (filelist. items [I]. tostring (). length> = prelen)
{
File. moveTo (FBD. selectedpath + "\" + pre + filelist. items [I]. tostring (). substring (prelen ));
}
Else
{
File. moveTo (FBD. selectedpath + "\" + pre + filelist. items [I]. tostring ());
}
}
MessageBox. Show ("renamed", "prompt", messageboxbuttons. OK, messageboxicon. information );
Listdirectory (FBD. selectedpath );
}
Catch
{
MessageBox. Show ("Renaming error", "prompt", messageboxbuttons. OK, messageboxicon. Error );
}
}
}

Renamw.l.rar

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.