I am a QA, I mention the bug after a habit, is to save the Jira address of the bug as a link exists locally, as follows:
Every day to manually put the date "" XX. XX "" added in, this repeated modification of the file name of the process is relatively boring, so I decided to write a form tool to implement, the form is as follows:
Click on select to jump out of the selected folder path interface, this place uses the FolderBrowserDialog control:
Then click on Modify to modify the selected folder path under all the file name.
The code for the entire form is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Text.RegularExpressions;namespacemodifynamesbylastwritetime{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } //Here is the code for the "select" button. Private voidSelectpath_click (Objectsender, EventArgs e) {FolderBrowserDialog FBD=NewFolderBrowserDialog (); if(FBD. ShowDialog () = =DialogResult.OK) {Pathtext.text=FBD. SelectedPath; }} //Here is the code for the "Modify" button. Private voidModifybutton_click (Objectsender, EventArgs e) {DirectoryInfo dir=NewDirectoryInfo (Pathtext.text); varFileinfos =dir. GetFiles (); Try { foreach(varFileInfoinchFileinfos) {
//If the file name conforms to the specification, the return value is true and does not change. if(Checkifhasbeenmodified (fileInfo)) {MessageBox.Show (Fileinfo.name+"is in the right format and no need to modify."); }
//otherwise, change. Else {
The format of the//convert LastWriteTime is "yyyy.mm.dd". stringLastWriteTime =string. Format ("{0:yyyy. MM.DD}", Fileinfo.lastwritetime);
//Add "" "on both sides of the lastwritetime after converting the format. stringFilenamepre ="""+ LastWriteTime +""";
//Modify the file name method. Fileinfo.moveto (Pathtext.text+"\\"+ Filenamepre +fileInfo.Name.ToString ()); }} MessageBox.Show ("Names of the files have been modified succesfully."); } Catch(Exception ex) {MessageBox.Show (ex). ToString ()); }} //This is a way to check if the file name conforms to the specification. Private Static BOOLcheckifhasbeenmodified (FileInfo file) {
//Match the canonical string with a regular expression. stringPattern =@"^\ "[0-9]+\. [0-9]+\. [0-9]+\] $"; Regex regex=NewRegex (pattern, regexoptions.ignorecase);
//Here if the length of the file name is less than 12 characters will throw an exception, so only if the file name length is greater than or equal to 12 after the further verification. if(file. Name.length >= A) { if(regex.) IsMatch (file. Name.substring (0, A))) {
the//Match specification returns TRUE. return true; }
//return False otherwise. Else { return false; } }
//return False otherwise. Else { return false; } } }}
The comments are more detailed and will not be explained. Hope to help and inspire you in your work.
The result of the operation is not ~ ~ Try it yourself.
Use C # WinForm to make a file name batch modifier