C # implementation of file change

xiaoxiao2021-03-06  41

In fact, it is very simple, but here still says, I hope to give the same C # newbie like me to help the background: I love to watch cartoon and comics, download the comics of Narutors in Naruto, and the image file naming method in the results directory It is 1, 2, ..., 10, .... 99,100, this is 1, 10, 100 ... not in the order of numbers, it looks relatively depressed. Therefore, I will write a small program of a batch file to be changed, and the file name is filled into 3 digits, followed by 001, 002, ..., 009, 010, .... The knowledge involved: String function; File and Directory functions; Environment and some interface core code are as follows: Very simple // Clear log this.listboxlog.Items.clear (); // Get all file name String under the current path [ ] FILES = Directory.getFiles (Environment.currentDirectory); Foreach (String FileName In Files) {// Last "/" INT LastPath = filename.lastIndexof ("//"); // Last "INT LastDot = Filename.lastIndexof ("."); // Purified file name length INT length = lastdot-lastpath-1; // file directory string XX / XX / XX / STRING BEGINPART = filename.substring (0, LastPath 1); // Pure file name String namenoext = filename.substring (LastPath 1, Length); // Extension String ext = filename.substring (LastDot); if (Length <3) {// Replenant to 3, constitute a new File name string namenew; if (length == 1) namenenew = "00" namenoext; else namenew = "0" namenoext; string fulnewname = beginpart namenew ext;

// Remove the name File.Move (FileName, Fullnewname);

// log this.listboxlog.items.add (namenoext "--->" namenew); this.listboxlog.selectedIndIndex = this.listboxlog.Items.count - 1;}

转载请注明原文地址:https://www.9cbs.com/read-82958.html

New Post(0)